brianvoe / slim-select

Slim advanced select dropdown
http://slimselectjs.com
MIT License
1.03k stars 195 forks source link

`getInstance` #527

Closed crespire closed 5 months ago

crespire commented 5 months ago

Is there an easy way for me to get an instance of SlimSelect that's already initialized?

For example, I'd like to adjust some available data options plus enable a select after it's already been initialized by other code:

// some page specific script
let ss = SlimSelect.getInstance("#select-id")

// replace all options
ss.options.data = [
  {text: 'Value 1'},
  {text: 'Value 2'},
  {text: 'Value 3'}
]

// or add additional options
ss.options.data << [{text: "New Option 1"}, {text: "New Option 2"}]
brianvoe commented 5 months ago

https://slimselectjs.com/settings#select