New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small fix for passing options in a select with grouping #390

Merged
1 commit merged into from Oct 12, 2010
Jump to file or symbol
Failed to load files and symbols.
+14 −2
Diff settings

Always

Just for now

Copy path View file
@@ -803,7 +803,7 @@ def select_input(method, options)
# The grouped_options_select is a bit counter intuitive and not optimised (mostly due to ActiveRecord).
# The formtastic user however shouldn't notice this too much.
raw_collection = find_raw_collection_for_column(method, options.reverse_merge(:find_options => { :include => options[:group_by] }))
label, value = detect_label_and_value_method!(raw_collection)
label, value = detect_label_and_value_method!(raw_collection, options)
group_collection = raw_collection.map { |option| option.send(options[:group_by]) }.uniq
group_label_method = options[:group_label_method] || detect_label_method(group_collection)
group_collection = group_collection.sort_by { |group_item| group_item.send(group_label_method) }
@@ -241,6 +241,8 @@
@form = semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label_method => :id ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :label_method => :login ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :label_method => :login, :group_label_method => :id ) )
end
end
@@ -261,11 +263,21 @@
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
end
it 'should have custom author labels' do
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
end
it 'should have custom author and group labels' do
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
end
end
it 'should have no duplicate groups' do
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag('form li select optgroup', :count => 4)
output_buffer.should have_tag('form li select optgroup', :count => 8)
end
it 'should sort the groups on the label method' do
ProTip! Use n and p to navigate between commits in a pull request.