Closed nd2s closed 6 years ago
Displaying or hiding input nothing does with it's validation, only validation attributes do.
If you don't need to validate specific input, you, obviously, do not add any validation attributes like required
.
Yeah, but these parts of the form can be toggled. If some select
shows value x then additional elements are displayed and should be validated. If not then they should just be ignored.
Like for asking about additional company information if the user selects "company user".
I can of course dynamically add/remove the validation attributes, but this seems rather messy.
So you have your custom logic and have to adapt your validation logic accordingly.
Hidden inputs with validation attributes are still validated by all browsers and per specification.
There might be cases when people want to validate hidden inputs as well, for example, textarea behind an editor.
Probably, the easiest option for you would be to use validateSection()
method manually.
So there is no simple general solution here and detecting if each input is visible during validation would bring too much needless complexity and delay. If you have some proposals, I am happy to discuss the implementation.
There is another use case. FX: using :valid selector with type="text" for a floating label. How can we validate that field for an email pattern. This can be done if we could control the pattern.
If you need to validate an email, you use type="email".
No thanks.
I am hiding part of a form with
display:none;
/.d-none
. bunny still validates these fields.