bluzky/nice-select2

How to apply for 2 or more selects in a form like state and city?

EduVillas opened this issue · 2 comments

How to apply for 2 or more selects in a form like state and city?

Thats possible

If you want to apply it to every select element, and they're all basic dropdowns/selects (no search, etc) you can get every element and iterate over them like this:

const e = document.getElementsByTagName("select");

for (var i = 0; i < e.length; i++) {
    NiceSelect.bind(e[i]);
}

I have one select that's slightly different, so I just added a condition within it.

function updateSelectFields() {

	const e = document.getElementsByTagName("select");
	
	for (var i = 0; i < e.length; i++) {
	
		if ( e[i].classList.contains('searchable') ) {
			NiceSelect.bind(e[i], {searchable: true, placeholder: 'Search'});
		} else {
			NiceSelect.bind(e[i]);
		}

	}
}