-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pass label_opts[for: ID]
when a custom ID is provided on ui_input
#126
Comments
Sounds like a bug in phoenix. It will produce labels that aren't associated with their inputs, right? But yes, we should definitely automatically pass along a custom input id to the label in |
Yes, exactly. I'm not sure if it's a legit bug because that would mean the Alternatively
and pass this id to the label as well 🤔 |
Why does even the id of the checkbox need to be different if |
In my case I had a list of checkboxes for one array field. For example |
Alright, then it makes sense. We could do both in
|
When passing an
ui_input
like this:Because of the checked value, the
id
attribute of the input will be autogenerated by Phoenix to bemyform_types_awesome
(see https://github.com/phoenixframework/phoenix_html/blob/d6c9d5369096540462d837e231f1a1eb5fb50042/lib/phoenix_html/form.ex#L1176). It suffixes the name with thechecked_value
.But the label helper (https://github.com/phoenixframework/phoenix_html/blob/d6c9d5369096540462d837e231f1a1eb5fb50042/lib/phoenix_html/form.ex#L1823) doesn't know about the
checked_value
and will havefor=myform_types
or so.As a result the input id and label's for do not match.
We can alleviate this by passing a custom id to
ui_input
but then it only works if you passlabel_opts=[for: CUSTOM_ID]
as well.I was wondering if
ui_input
should by default pass thelabel_opts[for: CUSTOM_ID]
automatically if anid
was given to theui_input
?The text was updated successfully, but these errors were encountered: