-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: bind null option and input values consistently #8328
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
fix: bind null option and input values consistently #8328
Conversation
@theodorejb is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
Before we merge this we need to see if this could be seen as a breaking change or not, and if so, if we want the changed behavior (probably) in 4.x. |
@dummdidumm I don't think this should be seen as a breaking change. It only has an effect on <option value={null}></option>
<option value={undefined}></option> It does not change the value bound to the parent select element. In the following example, the component's <select bind:value={foo} required>
<option value={null}></option>
<option>A</option>
</select> The only difference is that now the The one case I can think of that could potentially break is if someone has a select dropdown that isn't bound to a component value, e.g.: <select name="item">
<option value={null}></option>
<option value="a">A</option>
</select> Currently if the blank option is selected, the string "null" would be submitted for the <select name="item">
<option value="null">Null</option>
<option value="a">A</option>
</select> |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ade8ef4
to
7a00169
Compare
Null and undefined `value` bindings should always be set to an empty string. This allows native browser validation of `required` fields to work as expected with placeholder options. Placeholder options bound to null are necessary in forms where the field is conditionally required, and the bound value is posted to an API endpoint which requires it to be a nullable number or object rather than a string. Resolves sveltejs#8312
7a00169
to
e72d02d
Compare
A more likely scenario this change could break is if a select element is incorrectly <select bind:value={foo} required>
<option value={null}></option>
<option value="a">A</option>
<option value="b">B</option>
</select> If the form was intended to allow being submitted with the blank option selected, it currently works by happenstance because the empty option is given a non-empty value in the DOM. I can see this occurring if a developer blindly added But I would consider it more likely that the above code was intended not to submit when the blank option is selected, and merging this pull request will fix the bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Null and undefined `value` bindings should always be set to an empty string. This allows native browser validation of `required` fields to work as expected with placeholder options. Placeholder options bound to null are necessary in forms where the field is conditionally required, and the bound value is posted to an API endpoint which requires it to be a nullable number or object rather than a string. fixes #8312
Null and undefined
value
bindings should always be set to an empty string. This allows native browser validation ofrequired
fields to work as expected with placeholder options.Placeholder options bound to
null
are necessary in components where the field is conditionally required, and the bound value will be posted to an API endpoint which requires it to be a nullable number or object rather than a string.Resolves #8312