Skip to content
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

Grouped collection input #382

Merged

Conversation

semaperepelitsa
Copy link

I wanted to add grouped collection input so that you could do f.association :category, :collection => Category.roots, :group_method => :children. Rails has grouped_collection_select alongside with collection_select so it should be pretty similar to existing collection input.

The only thing I don't know how to deal with is how SimpleForm maps inputs to classes. Right now every input with collection option maps to select input type which maps to CollectionInput. I wish every input with group_method option map to the same select input type but also somehow map it to GroupedCollectionInput.

Do you like my idea and do you have any suggestions on the problem? Thanks.

@josevalim
Copy link
Contributor

Nice. I would just recommend that instead of checking :group_method, we could simply use :as to specify it:

f.input :authors, :as => :group_select, :collection => some_array

And then instead of having :group_method, we would simply use :value_method and :label_method which are already the official API used by collections.

class GroupedCollectionInput < CollectionInput
def input
group_label_method, label_method, value_method = detect_collection_methods
@builder.send(:"grouped_collection_#{input_type}", attribute_name, collection,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this input_type here, neither send. You can call only

@builder.grouped_collection_select(attribute_name, collection,
                                   group_method, group_label_method, value_method, label_method,
                                   input_options, input_html_options)

@semaperepelitsa
Copy link
Author

Good point, I will do that. Do you think group_select is a good name? I would call it grouped_select because you can't select groups actually and also Rails calls it grouped_collection_select.

We need to detect label for group collection separately from child collections because they are probably different
@josevalim
Copy link
Contributor

+1 for grouped_select

carlosantoniodasilva added a commit that referenced this pull request Jan 24, 2012
@carlosantoniodasilva carlosantoniodasilva merged commit 5b2f067 into heartcombo:v1.5 Jan 24, 2012
carlosantoniodasilva added a commit that referenced this pull request Jan 24, 2012
This reverts commit 5b2f067, reversing
changes made to 9ff998f.

This is going to be applied to master only, sorry.
carlosantoniodasilva added a commit that referenced this pull request Jan 24, 2012
Grouped collection input
Conflicts:

	test/inputs_test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants