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.

Home Page:https://bunnyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

validation: validating invisible inputs

nd2s opened this issue · comments

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

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.