Sha256: 9c2fc22aaecedeceb78d0ecd5d8bcbe354d20634f5aa473a1a33b4ddd039720d

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module DynamicFieldsets
  # Creates checkbox tags on a form
  #
  # Includes support for predefined field options and multiple selected answers
  class CheckboxField < Field
    acts_as_field_with_field_options
    acts_as_field_with_multiple_answers

    # 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
    # 
    #
    # @return [Hash] Data needed for the checkbox form partial
    def form_partial_locals(args)
      output = super
      output[:options] = []
      field_options.each do |option|
        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 => html_attribute_hash
        }
      end
      return output
    end 
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dynamic_fieldsets-0.1.6 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.5 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.4 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.3 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.2 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.1 app/models/dynamic_fieldsets/checkbox_field.rb
dynamic_fieldsets-0.1.0 app/models/dynamic_fieldsets/checkbox_field.rb