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, #serialized, #sort_as_numeric
Instance Method Summary collapse
Methods inherited from ResponseField
#audit_response, #has_length_validations?, #length_validations, #min_max_validations, #render_entry_for_table, #validate_response
Instance Method Details
#render_entry(value, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/models/formbuilder/response_field_radio.rb', line 41 def render_entry(value, opts = {}) str = value if (other = opts.try(:[], :entry).try(:responses).try(:[], "#{self.id}_other")) str += " (#{other})" end str end |
#render_input(value, opts = {}) ⇒ Object
9 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 |
# File 'app/models/formbuilder/response_field_radio.rb', line 9 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> <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='other-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(:responses).try(:[], "#{self[:id]}_other")}' /> </div> """ end str end |