Mevrael / bunny

BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
https://bunnyjs.com
MIT License
486 stars 39 forks source link

validation: validating invisible inputs #23

Closed nd2s closed 6 years ago

nd2s commented 6 years ago

I am hiding part of a form with display:none;/.d-none. bunny still validates these fields.

Mevrael commented 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.

nd2s commented 6 years ago

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.

Mevrael commented 6 years ago

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.

ghost commented 6 years ago

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.

Mevrael commented 6 years ago

If you need to validate an email, you use type="email".

ghost commented 6 years ago

No thanks.