Method: RecordSelectHelper#record_multi_select_field
- Defined in:
- lib/record_select/helpers/record_select_helper.rb
#record_multi_select_field(name, current, options = {}) ⇒ Object
Adds a RecordSelect-based form field for multiple selections. The values submit using a list of hidden inputs.
Arguments
name-
the input name that will be used to submit the selected records’ ids. empty brackets will be appended to the name.
current-
pass a collection of existing associated records
Options
controller-
The controller configured to provide the result set.
params-
A hash of extra URL parameters
id-
The id to use for the input. Defaults based on the input’s name.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/record_select/helpers/record_select_helper.rb', line 118 def record_multi_select_field(name, current, = {}) [:controller] ||= current.first.class.to_s.pluralize.underscore [:params] ||= {} [:id] ||= name.gsub(/[\[\]]/, '_') [:class] ||= '' [:class] << ' recordselect' .delete(:name) controller = assert_controller_responds(.delete(:controller)) params = .delete(:params) = {} [:current] = current.inject([]) { |memo, record| memo.push({:id => record.id, :label => label_for_field(record, controller)}) } html = text_field_tag("#{name}[]", nil, .merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false")) html << content_tag('ul', '', :class => 'record-select-list'); # js identifier so we can talk to it. = "rs_%s" % name.gsub(/[\[\]]/, '_').chomp('_') url = url_for({:action => :browse, :controller => controller.controller_path, :escape => false}.merge(params)) html << javascript_tag("#{} = new RecordSelect.Multiple(#{[:id].to_json}, #{url.to_json}, #{.to_json});") return html end |