How to get a handle for an initialized Choices element
See original GitHub issueIf I have initialized my Choices element in the following way:
new Choices(document.querySelector(#choices'));
Is there a way to access the initialized Choices element somewhere else in the code if I don’t have a reference to the original value? As far as I know, using new Choices
always returns a new, uninitialized value.
The use case could be, for example, that I want to programmatically set the value (.setValue()
)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:24
Top Results From Across the Web
Handling Events
Most events are called on a specific DOM element and then propagate to that element's ancestors, allowing handlers associated with those elements to...
Read more >Choices JS Re-Initialize is not working for dynamic Row add
I've faced similar kind of issue first i make each element with unique class and then call it from JS code, My code...
Read more >Add Choices.js for tags multi-select | Part 25 - YouTube
In this lesson, we will add the choices.js for tags multi-selectStarter Template: GitHub Link: ...
Read more >EventTarget.addEventListener() - Web APIs | MDN
It works on any event target, not just HTML or SVG elements. ... when both elements have registered a handle for that event....
Read more >7 Tips to Handle undefined in JavaScript
an uninitialized variable number; a non-existing object property movie.year; or a non-existing array element movies[3]. are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found that you can set the value of an existing Choices instance that you cannot access but triggering the mousedown event on the item with the value for which you’re looking:
handleSelect (obj, value) { let selectFields = obj.closest('.choices').querySelectorAll('.choices__item--selectable') for (let i = 0; i < selectFields.length; i++) { if (selectFields[i].dataset.value === value) { console.warn(selectFields[i].dataset.value) selectFields[i].dispatchEvent(new Event('mousedown')) } } }
(obj here is a select element)Hi,
The point was exactly that I don’t have the option to assign it to a variable.
On Wed, 28 Mar 2018, 17:31 Josh Johnson, notifications@github.com wrote: