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

Consider exception to no-attribute-value if type is checkbox/radio #122

Open
WickyNilliams opened this issue Jan 27, 2022 · 0 comments
Open

Comments

@WickyNilliams
Copy link

WickyNilliams commented Jan 27, 2022

Checkboxes and radios are unique in that they have a default value of "on". If you use property binding, you cannot take advantage of this:

html`<input type="radio" name="test" .value=${undefined} />` // will submit as string "undefined"
html`<input type="radio" name="test" .value=${null} />` // will submit as empty string ""
html`<input type="radio" name="test" .value=${""} />` // will submit as empty string ""

Whereas if you use the attribute binding, you can conditionally render the attribute and fallback to the default:

html`<input type="radio" name="test" value=${ifDefined(value)} />` // will submit as "on"

In my testing this works correctly even if a value is initially set, and later changed, or if attribute is later removed.

Happy to attempt a PR if you don't object

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

No branches or pull requests

1 participant