Class: Formbuilder::ResponseFieldRadio
- Inherits:
-
ResponseField
- Object
- ActiveRecord::Base
- ResponseField
- Formbuilder::ResponseFieldRadio
- Defined in:
- app/models/formbuilder/response_field_radio.rb
Constant Summary
Constants inherited from ResponseField
Formbuilder::ResponseField::ALLOWED_PARAMS
Instance Attribute Summary
Attributes inherited from ResponseField
#cid, #field_type, #input_field, #options_field, #search_type, #serialized, #sort_as_numeric
Instance Method Summary collapse
- #render_entry(value, opts = {}) ⇒ Object
- #render_input(value, opts = {}) ⇒ Object
- #transform_raw_value(raw_value, entry, opts = {}) ⇒ Object
Methods inherited from ResponseField
#audit_response, #before_response_destroyed, #has_length_validations?, #length_validations, #max, #maxlength, #min, #min_max_length_units, #min_max_validations, #minlength, #normalize_response, #options_array, #render_entry_text, #sortable_value, #validate_response
Instance Method Details
#render_entry(value, opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/models/formbuilder/response_field_radio.rb', line 42 def render_entry(value, opts = {}) str = value if (other = opts.try(:[], :entry).try(:get_responses).try(:[], "#{self.id}_other")) str += " (#{other})" end str end |
#render_input(value, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/formbuilder/response_field_radio.rb', line 10 def render_input(value, opts = {}) value ||= {} str = (self[:field_options]["options"] || []).each_with_index.map do |option, i| checked = (value == option["label"]) || (value.blank? && option["checked"]) """ <label class='fb-option'> <input type='radio' name='response_fields[#{self[:id]}]' #{checked ? 'checked' : ''} value='#{option['label']}' /> #{option['label']} </label> """ end.join('') if self[:field_options]['include_other_option'] str += """ <div class='fb-option'> <label> <input type='radio' name='response_fields[#{self[:id]}]' #{value == 'Other' ? 'checked' : ''} value='Other' /> Other </label> <input type='text' name='response_fields[#{self[:id]}_other]' value='#{opts.try(:[], :entry).try(:get_responses).try(:[], "#{self[:id]}_other")}' /> </div> """ end str end |
#transform_raw_value(raw_value, entry, opts = {}) ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/formbuilder/response_field_radio.rb', line 52 def transform_raw_value(raw_value, entry, opts = {}) entry.get_responses["#{self.id}_other"] = (raw_value == 'Other') ? opts[:response_field_params]["#{self.id}_other"] : nil raw_value end |