-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Collection radio buttons / check boxes helpers #4851
Merged
josevalim
merged 22 commits into
rails:master
from
carlosantoniodasilva:collection-helpers
Feb 2, 2012
Merged
Collection radio buttons / check boxes helpers #4851
josevalim
merged 22 commits into
rails:master
from
carlosantoniodasilva:collection-helpers
Feb 2, 2012
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
module [Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
collection_radio_buttons [Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
* Extract value sanitization from default name and id method and new collection helpers; * No need to sanitize value in default name and id always; * Improve value_before_type_cast to avoid concating the same method name string twice. [Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
This will make it easy for the user to handle how check box/radio and labels should be generated, abstracting any text/value/default html options required to make it work. [Carlos Antonio da Silva + Rafael Mendonça França]
…itance [Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
/cc @josevalim |
@jeremy it looks good to me, let's merge? |
Nice job, especially with updated docs and guide. There are a lot of other refactorings and style changes included, too, making it hard to review the code carefully. 👍 here but please do separate pulls for refactoring and style changes next time! |
@jeremy thanks, we will be paying more attention to that from now on. |
And options_from_collection_for_select as well. [Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
[Carlos Antonio da Silva + Rafael Mendonça França]
collection_radio_buttons [Carlos Antonio da Silva + Rafael Mendonça França]
josevalim
pushed a commit
that referenced
this pull request
Feb 2, 2012
Collection radio buttons / check boxes helpers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@rafaelfranca and I have been working to move SimpleForm's
collection_radio_buttons
andcollection_check_boxes
helpers to Rails. They work in a similar way tocollecion_select
, but generating a collection of radio_button/check_box + label for each item in the given collection. Here is an example usage:It'd output something like:
It is possible to customize the output by giving a block to the helper. This block receives an argument, which is an "special builder" that is able to generate a label and radio_button/check_box for the given item context. For instance:
The helpers
label
andcheck_box
/radio_button
are available inside the block, scoped to the current element being rendered, that also accepts extra html options. The currenttext
andvalue
methods are also available for use, allowing better customization.This PR also adds the ability for
collection_select
to receive proc values astext_method
andvalue_method
, something we've added to collection check_boxes/radio_buttons/select helpers in SimpleForm.Thanks.