Class: DynamicFieldsets::MultipleSelectField

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

Overview

A select field that handles multiple selections

Even though it just uses a select tag helper with multiple: true, the backend is quite different from the select field. It uses the multiple_answers mixin and all of the value and default methods return arrays instead of strings.

Instance Method Summary collapse

Methods inherited from Field

#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?, #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

#collect_default_valuesArray

this returns field option ids based on the field default values due to funness with field options

there is a good chance this is only needed due to a bug in multiple select’s save default method We may need to take a look at this in the future. I think it could be moved to a mixin. (JH 2-28-2012)

Returns:

  • (Array)

    An array of field option ids that correspond to the field defaults



32
33
34
35
36
37
38
39
40
# File 'app/models/dynamic_fieldsets/multiple_select_field.rb', line 32

def collect_default_values
  output = []
  field_defaults.each do |default|
    # find a field option with the same name as the default
    # add it's id to the output
    output << field_options.select { |option| option.name == default.value }.first.id
  end
  return output
end

#form_partial_locals(args) ⇒ Hash

Returns data for the form partial.

Returns:

  • (Hash)

    data for the form partial



19
20
21
22
23
24
# File 'app/models/dynamic_fieldsets/multiple_select_field.rb', line 19

def form_partial_locals(args)
  super.merge!({
    :selected_ids => values_or_defaults_for_form(args[:values]),
    :collection => self.options
  })
end

#html_attribute_hashHash

Returns Sets multiple to true along with the standard arguments.

Returns:

  • (Hash)

    Sets multiple to true along with the standard arguments



12
13
14
15
16
# File 'app/models/dynamic_fieldsets/multiple_select_field.rb', line 12

def html_attribute_hash
  super.merge!({
    :multiple => true
  })
end