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

Possible enhancement #17

Open
AzzaAzza69 opened this issue Nov 22, 2018 · 3 comments
Open

Possible enhancement #17

AzzaAzza69 opened this issue Nov 22, 2018 · 3 comments

Comments

@AzzaAzza69
Copy link

Instead of having the Note:
"This plugin requires a unique ID on the DOM element to work (though you don't have to select by ID with jQuery when you initialize this)."

Utilise the jquery method .uniqueId() instead!

@JacobEvelyn
Copy link
Member

Thanks for the suggestion, @AzzaAzza69! I didn't know about .uniqueId() but it looks like exactly what we want. I'll see if I can get this working in the next day or so. It seems like it might be a more stable change than #15.

@JacobEvelyn
Copy link
Member

Hi @AzzaAzza69. Unfortunately I haven't been able to get this to work.

This is because at the time the user calls .maximizeSelect2Height(), the .select2() function has already been called. When .select2() is called, if the element doesn't have an id then Select2 uses a randomly generated ID for its internal naming, without setting that random id on the original element.

That means that by the time our .maximizeSelect2Height() code runs, even if the <select> DOM element that we have access to from our function has no id, Select2 has already given its DOM elements random id fields, and we have no way (as far as I can tell) to get those id fields from the <select> element.

I hope that makes sense. Please feel free to try implementing this yourself—it might be that there's something I missed!

@dvtan
Copy link

dvtan commented May 19, 2019

@JacobEvelyn maybe set the ID in a wrapper? So instead of $el.select2(options).maximizeSelect2Height(), it could just be $el.maximizeSelect2Height(options)

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