Class: DynamicFieldsets::CheckboxField

Inherits:
Field
  • Object
show all
Defined in:
app/models/dynamic_fieldsets/checkbox_field.rb

Overview

Creates checkbox tags on a form

Includes support for predefined field options and multiple selected answers

Instance Method Summary collapse

Methods inherited from Field

#collect_default_values, #collect_field_records_by_fsa_and_fsc, descendant_collection, descendants, #display_type, #form_footer_partial, #form_header_partial, #form_partial, #get_value_for_show, #get_values_using_fsa_and_fsc, #has_defaults?, #html_attribute_hash, #in_use?, #show_footer_partial, #show_header_partial, #show_partial, #show_partial_locals, #update_field_records, #use_form_footer_partial?, #use_form_header_partial?, #use_show_footer_partial?, #use_show_header_partial?, #uses_field_options?

Instance Method Details

#form_partial_locals(args) ⇒ Hash

Note that the checkbox needs individual data for each of the included options This means that some things, such as the name are duplicated for each field option

Returns:

  • (Hash)

    Data needed for the checkbox form partial



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/dynamic_fieldsets/checkbox_field.rb', line 14

def form_partial_locals(args)
  output = super
  output[:options] = []
  field_options.each do |option|
    # rails is screwing up the ids just for the checkbox field
    # this is a (hopefully) temporary solution/hack to get the id right (JH 3-29-2012)
    # another possibility would be to update the html attributes method and add fsa and fsc arguments to it
    adjusted_html_attributes = html_attribute_hash.merge({
      :id => "#{DynamicFieldsets.config.form_fieldset_associator_prefix}#{args[:fsa].id}_#{DynamicFieldsets.config.form_field_prefix}#{args[:fieldset_child].id}_#{option.id.to_s}"
    });

    output[:options] << {
      :name => "#{DynamicFieldsets.config.form_fieldset_associator_prefix}#{args[:fsa].id}[#{DynamicFieldsets.config.form_field_prefix}#{args[:fieldset_child].id}][]",
      :value => option.id.to_s,
      :checked => values_or_defaults_for_form(args[:values]).include?(option.id.to_s),
      :label => option.name,
      :html_attributes => adjusted_html_attributes,
    }
  end
  return output
end