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

Allow value option on labels for easier building of dynamic radio buttons/checkboxes #203

Conversation

@johantell
Copy link

@johantell johantell commented Mar 17, 2018

This will allow labels to be used with dynamically created radiobuttons and checkboxes to have the correct prefix.

For example this will now be allowed:

radio_button :user, :level, :gold
label :user, :level, value: :gold

which will produce:

<input id="user_level_gold" name="user[level]" type="radio" value="gold">
<label for="user_level_gold"></label>

It'll be an improvement over the current way where you'd either have to build the for attribute yourself.

Could be a followup on #195

johantell added 3 commits Mar 17, 2018
This will allow labels to be used with dynamically created
radiobuttons and checkboxes to have the correct prefix
@josevalim
Copy link
Member

@josevalim josevalim commented Mar 17, 2018

Thanks @mintcore! I see the need for this feature but I don't like using :value because maybe something somewhere expects a value attribute in labels and this would make it impossible. We need a way to not clobber the attribute options but I don't have an idea right now.

Thoughts?

@johantell
Copy link
Author

@johantell johantell commented Mar 17, 2018

It's a good point @josevalim! I've thought about that some too but wanted to hear more opinions on it.

I'll take some time to think and get back on it when i've got some new ideas!

@josevalim
Copy link
Member

@josevalim josevalim commented Mar 17, 2018

One option is to introduce this:

label :user do 
  radio_button :user, :level, :gold
end

Because if the input is inside the label, you don't need for.

@johantell
Copy link
Author

@johantell johantell commented Mar 17, 2018

One way could be to allow field to be a tuple

label :user, {:level, :gold} do 
  radio_button :user, :level, :gold
end

But it does not feel like something anyone would figure out by themselves and therefore not that good.

@johantell
Copy link
Author

@johantell johantell commented Mar 17, 2018

That is true! While it covers many cases I'm afraid it won't cover them all.

I better update the code above to show that case instead of the wrapped one

@josevalim
Copy link
Member

@josevalim josevalim commented Mar 17, 2018

@mintcore for the remaining cases you can always pass for: input_id(...).

@johantell
Copy link
Author

@johantell johantell commented Mar 17, 2018

@josevalim True! So that basically means we can close this, right?

@josevalim
Copy link
Member

@josevalim josevalim commented Mar 17, 2018

@mintcore not quite because we don't support label block but I am adding it now. :)

@johantell
Copy link
Author

@johantell johantell commented Mar 17, 2018

@josevalim Let me know if there is anything more I can do!

@josevalim
Copy link
Member

@josevalim josevalim commented Mar 17, 2018

Now in master, thanks! :)

@josevalim josevalim closed this Mar 17, 2018
@johantell johantell deleted the johantell:feature/value_option_for_radio_and_checkboxes branch Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.