I have an input with type password with minLength 8, and i have a toggle to change the type to text (password toggle).
when i type with length < 8 and press submit, it prevent to submit. but, when i toggle the password so it change the type to text and submit the form, it can submitted. btw i using useRef()
React version:
react: ^17.0.1
react-dom: ^17.0.1
Link to code example: DEMO
The form get submitted even when it under minLength
The form not get submitted when it under minLength
Thanks for the report.
I can spot two issues:
minLength="3" not 8.minLength is not supported in IE 11: https://caniuse.com/input-minlengthI'm using mac os 10.14.6 and browser Safari 13.0.5 (14608.5.12)
i forgot something, don't type any characters after toggle it
btw, when i try with Chrome 86.0.4240.183 it works fine. i think it happen only in safari
Thanks, I can reproduce this.
Generally any validation is ignored if the input is pristine. If you submit the form without typing anything the minLength is ignored.
Safari properly marks the form as invalid if you typed something that doesn't pass all constraints. However, when the type changes Safari seems to consider the input pristine. Therefore an invalid value is submitted if the type changed after typing is complete.
The question is if React can or should fix this quirk or whether Safari should fix this.
Edit:
Minimal repro without any react: https://codesandbox.io/s/condescending-bhabha-n4374?file=/src/index.js
If you need this behavior I suggest filing a bug with Safari.
Most helpful comment
Thanks, I can reproduce this.
Generally any validation is ignored if the input is pristine. If you submit the form without typing anything the
minLengthis ignored.Safari properly marks the form as invalid if you typed something that doesn't pass all constraints. However, when the
typechanges Safari seems to consider the input pristine. Therefore an invalid value is submitted if thetypechanged after typing is complete.The question is if React can or should fix this quirk or whether Safari should fix this.
Edit:
Minimal repro without any react: https://codesandbox.io/s/condescending-bhabha-n4374?file=/src/index.js
If you need this behavior I suggest filing a bug with Safari.