Open sandric opened 5 years ago
@sandric: Not completely sure about your example, but I had spent some time getting programmatic additions of items to work, resulting in the example in section 'How Has This Been Tested?' in https://github.com/jshjohnson/Choices/pull/594 . You may want to take a look at the lines before and after //console.log('Adding choice ',newItem);
. Does that help?
triggerEvent
works and is undocumented (NB: doesn't actually edit the data/list). Make sure to pass in an identifier so you don't end up with an infinite loop -- e.g.:
choiceList.passedElement.triggerEvent('removeItem', {id: 3, value: 'test', programmatic: true})
hy @agamemnus i've tried this several times, but i dont know why i cant delete an item.
var comp = new Choices(document.querySelector("#w0"), {
choices:[{"value":"Pacific\/Midway","label":"(UTC -11:00) Pacific\/Midway"},
{"value":"Pacific\/Niue","label":"(UTC -11:00) Pacific\/Niue"}],
removeItemButton:true,
searchFields:["label","value"],
shouldSort:true,
silent:true,
//removeItems:true
});
comp.passedElement.triggerEvent('removeItem', {id: 2, value: 'Pacific\/Niue', label: '(UTC -11:00) Pacific\/Niue', groupId: -1}); //still cant delete the item
`
IDK I'll take a look look if I have time
On Wed, Jan 3, 2024, 6:03 PM hyuuks @.***> wrote:
hy @agamemnus https://github.com/agamemnus i've tried this several times, but i dont know why i cant delete an item.
var comp = new Choices(document.querySelector("#w0"), { choices:[{"value":"Pacific\/Midway","label":"(UTC -11:00) Pacific\/Midway"}, {"value":"Pacific\/Niue","label":"(UTC -11:00) Pacific\/Niue"}], removeItemButton:true, searchFields:["label","value"], shouldSort:true, silent:true,
//removeItems:true});
eventMenu.passedElement.triggerEvent('removeItem', {id: 2, value: 'Pacific\/Niue', label: '(UTC -11:00) Pacific\/Niue', groupId: -1}); //still cant delete the item `
— Reply to this email directly, view it on GitHub https://github.com/Choices-js/Choices/issues/634#issuecomment-1876088192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYUSWDL6IRXFQBTE4LC4ELYMXPVNAVCNFSM4ITTEGR2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXGYYDQOBRHEZA . You are receiving this because you were mentioned.Message ID: @.***>
I having trouble understanding pretty basic thing as I think - how to add or remove options to/from select? In one issue I found
triggerEvent(this.passedElement, 'addItem', params)
line for addition, but as I understood api changed a bit so you should use instead:choiceSelect.passedElement.triggerEvent('addItem', {id: 3, value: 'test'})
?So my full example is this:
But I get no new elements, so what am I doing wrong?
P.S. I also tried with no luck either:
choiceSelect.passedElement.element.dispatchEvent(new Event('addItem', {id: 3, value: 'someval'}))