When passing an ui_input like this:
<.ui_input
form={f}
field={:types}
type={:checkbox}
name={"#{input_name(f, :types)}[]"}
value={"awesome"}
checked_value={"awesome"}
/>
Because of the checked value, the id attribute of the input will be autogenerated by Phoenix to be myform_types_awesome (see https://github.com/phoenixframework/phoenix_html/blob/d6c9d5369096540462d837e231f1a1eb5fb50042/lib/phoenix_html/form.ex#L1176). It suffixes the name with the checked_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 have for=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 pass label_opts=[for: CUSTOM_ID] as well.
I was wondering if ui_input should by default pass the label_opts[for: CUSTOM_ID] automatically if an id was given to the ui_input?
When passing an
ui_inputlike this:Because of the checked value, the
idattribute 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_valueand will havefor=myform_typesor 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_inputbut then it only works if you passlabel_opts=[for: CUSTOM_ID]as well.I was wondering if
ui_inputshould by default pass thelabel_opts[for: CUSTOM_ID]automatically if anidwas given to theui_input?