Class: Formbuilder::ResponseFieldDropdown

Inherits:
ResponseField
  • Object
show all
Defined in:
app/models/formbuilder/response_field_dropdown.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



25
26
27
# File 'app/models/formbuilder/response_field_dropdown.rb', line 25

def render_entry(value, opts = {})
  value
end

#render_input(value, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/formbuilder/response_field_dropdown.rb', line 9

def render_input(value, opts = {})
  options = ""
  options += "<option></option>" if self[:field_options]['include_blank_option']

  Array(self[:field_options]['options']).each_with_index do |option, i|
    selected = (value == option["label"]) || (value.blank? && option["checked"])
    options += "<option value='#{option["label"]}' #{selected ? 'selected' : ''}>#{option['label']}</option>"
  end

  """
    <select name='response_fields[#{self[:id]}]'>
      #{options}
    </select>
  """
end