Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Can't get the selectr instance after instantiated #87

Closed
GlauberrBatista opened this issue Nov 21, 2018 · 2 comments
Closed

Can't get the selectr instance after instantiated #87

GlauberrBatista opened this issue Nov 21, 2018 · 2 comments

Comments

@GlauberrBatista
Copy link

Hi,
I'm initializing all the selects in my page that contains a specific data attribute (e.g., data-context="selectr") on page load. However, I'm not storing the instances in variables, since there are several selects on that page. So, I need to update/enable/disable some selects and I didn't find a way to get the instance attached to the select component. By doing Selectr('#foo') I get an error and creating a new instance with new Selectr('#foo') will generate another selectr.
In Select2, for instance, if we call $el.select2('#foo') we will get the instance attached to that select, but I didn't find anything like this in selectr.

Is there a way to get the selectr instance attached to a select, or is this a bug? Or is it by design?

@Mobius1
Copy link
Owner

Mobius1 commented Nov 21, 2018

This is as simple as adding this.el.selectr = this; so you can access the selectr property on the select element when needed.

I'll add it for the next release.

@Mobius1
Copy link
Owner

Mobius1 commented Nov 21, 2018

As of v2.4.8, you can access the instance:

const el = document.getElementById("mySelect");

// create anonymous instance
new Selectr(el, config);

// get the instance
el.selectr

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

No branches or pull requests

2 participants