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

Use the proper boolean attributes in HTML form tags. #1598

Merged
merged 1 commit into from
Nov 1, 2021
Merged

Conversation

jwoertink
Copy link
Member

Purpose

Fixes #1560

Description

We had been using checked="true" or selected="true" which according to these docs is invalid.

To be clear, the values "true" and "false" are not allowed on boolean attributes.

Checklist

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

if field.param == checked_value
html_options = merge_options(html_options, {"checked" => "true"})
attrs = attrs | [:checked]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one could technically call <<, but I just kept it consistent with the other forms in this file.

@@ -80,7 +81,7 @@ module Lucky::InputHelpers
def checkbox(field : Avram::PermittedAttribute(Bool), attrs : Array(Symbol), **html_options) : Nil
unchecked_value = "false"
if field.value
html_options = merge_options(html_options, {"checked" => "true"})
attrs = attrs | [:checked]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use << here because arguments are passed by reference. Which means that when we pass EMPTY_BOOLEAN_ATTRIBUTES, it would pass that to other methods causing ALL radios/checkboxes to be marked as checked

@@ -211,6 +212,7 @@ module Lucky::InputHelpers
"value" => input_value(field),
}.merge(input_overrides)
update_array_id_counter!(field)
attrs.uniq!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case so you don't accidentally send over duplicate attrs...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML is pretty fast and loose with it's attributes, especially in the age of React and other front end frameworks which make up their own elements...are we sure there is no use case for passing the same attribute more than once to a tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only prevent a tag being rendered like <input ... checked checked required required />. I'm sure browsers would just ignore it, so it's probably not required, but in the case of some random browser that breaks due to it, I figured why not? 🤷‍♂️

@jwoertink jwoertink merged commit c916f61 into master Nov 1, 2021
@jwoertink jwoertink deleted the issues/1560 branch November 1, 2021 19:08
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.

Use the proper bool attribute on opption selected
3 participants