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

Make single checkboxes more user friendly #186

Closed
3 tasks
peteryates opened this issue Aug 31, 2020 · 1 comment · Fixed by #192
Closed
3 tasks

Make single checkboxes more user friendly #186

peteryates opened this issue Aug 31, 2020 · 1 comment · Fixed by #192
Labels
bug Something isn't working

Comments

@peteryates
Copy link
Member

peteryates commented Aug 31, 2020

Currently it appears that when creating a single check box the hidden field that should be rendered automatically by the Rails #check_box helper we're wrapping isn't present in the output.

I'm not sure why this happens, if there's a good reason it's not (and not just a misconfiguration bug) then it's probably a good idea to add the hidden field in this library when multiple: false.

Currently this is kind of mitigated by a note in the guide, but that can definitely be improved 😅

= f.govuk_check_box(:awesome, true, multiple: false, label: -> { 'Awesome?' })
<div class="govuk-checkboxes__item">
  <input id="person-awesome-true-field" class="govuk-checkboxes__input" type="checkbox" value="true" checked="checked" name="person[awesome]">
  <label for="person-awesome-true-field" class="govuk-label govuk-checkboxes__label">Awesome?</label>
</div>
  • Work out why with a single checkbox the hidden field that should be generated by Rails isn't there
  • Fix it if we've done something wrong. If not, take care of rendering it ourselves
  • Update the documentation accordingly
@peteryates peteryates added the 2.0.0 Version 2.0.0 label Aug 31, 2020
@peteryates
Copy link
Member Author

So, it seems that Rails only renders the necessary hidden field when the false value is 0, when the helper's called with false the output is omitted 🤦

[3] pry(#<GOVUKDesignSystemFormBuilder::Elements::CheckBoxes::FieldsetCheckBox>)> @builder.check_box(@attribute_name, {}, @value, false)
=> "<input type=\"checkbox\" value=\"11\" name=\"person[projects]\" id=\"person_projects\" />"
[4] pry(#<GOVUKDesignSystemFormBuilder::Elements::CheckBoxes::FieldsetCheckBox>)> @builder.check_box(@attribute_name, {}, @value, 0)
=> "<input name=\"person[projects]\" type=\"hidden\" value=\"0\" /><input type=\"checkbox\" value=\"11\" name=\"person[projects]\" id=\"person_projects\" />"

@peteryates peteryates added bug Something isn't working and removed 2.0.0 Version 2.0.0 labels Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant