Skip to content

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

Closed
johantell wants to merge 3 commits into
phoenixframework:masterfrom
johantell:feature/value_option_for_radio_and_checkboxes
Closed

Allow value option on labels for easier building of dynamic radio buttons/checkboxes#203
johantell wants to merge 3 commits into
phoenixframework:masterfrom
johantell:feature/value_option_for_radio_and_checkboxes

Conversation

@johantell
Copy link
Copy Markdown

@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

This will allow labels to be used with dynamically created
radiobuttons and checkboxes to have the correct prefix
@josevalim
Copy link
Copy Markdown
Member

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
Copy Markdown
Author

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
Copy Markdown
Member

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
Copy Markdown
Author

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
Copy Markdown
Author

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
Copy Markdown
Member

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

@johantell
Copy link
Copy Markdown
Author

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

@josevalim
Copy link
Copy Markdown
Member

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

@johantell
Copy link
Copy Markdown
Author

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

@josevalim
Copy link
Copy Markdown
Member

Now in master, thanks! :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants