bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
370 stars 61 forks source link

Support for "required" attributes. #66

Open QuintinS opened 1 year ago

QuintinS commented 1 year ago

I've implemented this in a project, but when I wanted to add validation to a form field using NiceSelect2, it turned out that the required attribute from the input isn't implemented in a way that makes the input validatable.

The "required" is kept on the original select, which is hidden, which in turn causes the following error when the form is submitted:

An invalid form control with name='customer[note][Veterinarian]' is not focusable.

It would be great if this library implemented this (baseline feature of HTML) in some way!

Realmaker commented 1 year ago

I have the same issue.

Quick and dirty solution -> use this styles:

select.niceSelect { display: block !important; width: 0px !important; height: 0px !important; opacity: 0 !important; }