Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EduVillas opened this issue Feb 26, 2022 · 2 comments
Closed

Comments

@EduVillas
Copy link

EduVillas commented Feb 26, 2022

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

@Tsjippy
Copy link
Collaborator

Tsjippy commented Jan 13, 2023

Thats possible

@Tsjippy Tsjippy closed this as completed Jan 13, 2023
@mattneal-stafflink
Copy link

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]);
		}

	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants