bluzky / nice-select2

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

Hitting "return/enter" key submits the form instead of selecting an option in search. #56

Open mattneal-stafflink opened 1 year ago

mattneal-stafflink commented 1 year ago

As above. In other single/multi select fields, hitting enter selects the option. In Nice-Select2, it submits the form. There should be a way to prevent this from happening. For the moment I'm just using my own solution:

    NiceSelect.bind(
        document.getElementById('property_location'),
        {searchable: true, placeholder: 'Search'}
    );

    const searchForm = document.getElementById('property-search-form');

    searchForm.addEventListener('submit', function(e) {
        if ( searchForm.querySelector('.nice-select-search:focus') ) {
            e.preventDefault();
            document.getElementById("PrimarySubmit").focus();
        }
    });

Which works fine, but I feel like this should be the default...