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

Label's for attribute doesn't match the id when nil is given in collection #1840

Open
masasakano opened this issue Apr 21, 2024 · 0 comments

Comments

@masasakano
Copy link

Environment

  • Ruby 3.1.2p20
  • Rails 7.0.8
  • Simple Form 5.3.0

Current behavior

When a collection is explicitly given to radio-buttons and one of the values is nil, the generated for label for the nil one does not match its corresponding id with a difference of a single underscore character. For example,

<%= form.input :my_method, as: :radio_buttons, label: "ABC",
      collection: [['Yes', true], ['Undefined', nil]], checked: nil %>

for Model generates

<fieldset class="form-group radio_buttons model_my_method">
<legend class="col-form-label pt-0">ABC</legend>
<input type="hidden" name="model[my_method]" value="" autocomplete="off" />
<!-- Valid one for "true" -->
<div class="form-check">
  <input class="form-check-input radio_buttons required" type="radio" value="true" name="model[my_method]"
    id="model_my_method_true" />
  <label class="form-check-label collection_radio_buttons"
    for="model_my_method_true">Yes</label>
</div>

<!-- Invalid one for "nil" -->
<div class="form-check">
  <input class="form-check-input radio_buttons required" type="radio" checked="checked" name="model[my_method]"
    id="model_my_method" />
  <label class="form-check-label collection_radio_buttons"
    for="model_my_method_">Undefined</label>
</div>

The second pair of input and label corresponds to the nil-parameter. As you see, the for has a trailing _, whereas that for id does not, and so they are not consistent.

Expected behavior

The label and corresponding ID values must exactly agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant