-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Weird input validation breakage when using $$props #4418
Comments
Do remember that |
It is not, though: https://svelte.dev/docs#Attributes_and_props (...scroll to the end of section "Attributes and props") Also this: #2528 |
I don't think this has anything to do with the spread operator. It seems this has something to do with setting the value of an input element with javascript (in this case, by the bind directive). |
@PatrickG Do you mean, that if you type Both of those inputs definitely set the input's value via JavaScript using Svelte's two-way binding, so that is not the cause. The other one works just fine, the other one doesn't, and the only difference is the use of Due to this:
...I believe the only way around this issue is to introduce an More about that here: #3015 (comment) |
Only the input I'm currently typing shows the invalid state. But it doesn't matter which one. If I type in the input with {...props} that shows the invalid state, if I type in the one with {maxlength} that shows the invalid state. If you use two inputs with {maxlength}, it is the same problem: https://svelte.dev/repl/d3ed4891c78042df86f447d67a3f0160?version=3.18.2 With the pattern attribute instead of the maxlength, it works: https://svelte.dev/repl/6e99e8920b1c4d229e70d1918fe6b9d5?version=3.18.2
It is not the reassinged props that makes the problem. its the assignment of |
@PatrickG it seems I jumped into hasty conclusions when producing the repro from our actual code. Maybe this REPL is a better starting point: https://svelte.dev/repl/361a85968bd5458a920c62bf610e8a9a?version=3.18.2 It seems using 2-way-binding for the value keeps things working, but using Using |
This should be fixed now in 3.24.0 - https://svelte.dev/repl/361a85968bd5458a920c62bf610e8a9a?version=3.24.0 |
Describe the bug
When passing down unknown props using
$$props
, like so (Svelma does this, maybe other component libs too?)...the standard HTML input validation fails when using
minlength
, like soThe produced HTML seems fine, the input element has both
required
andminlength="5"
set, but the validation doesn't kick in if the input has fewer than 5 characters. If the input is empty, validation works.If I remove the reactive
$: props...
assignment and instead passrequired
andminlength
manually, the validation starts working again.To Reproduce
https://svelte.dev/repl/8da0a0fdbc3245d19e57aeab025e763f?version=3.18.2
Type something into the input. The other one correctly displays the
:invalid
style, the other one doesn't.Expected behavior
I'd expect the html input validation to work even when using
$: props = ...
.Information about your Svelte project:
All latest Safari, Firefox, Chrome
Mac OS Mojave
Svelte version 3.18.2, but checked that the issue exists at least down to 3.7.0
Severity
Breaks validation, but in a very sneaky way, so I'd give it a 7/10 on severity index!
The text was updated successfully, but these errors were encountered: