Replies: 4 comments
-
Thats an interesting find. Please submit this as an issue(or better submit a pr) and it will get into a better pipeline for development. |
Beta Was this translation helpful? Give feedback.
-
i added a native select to the fiddle. it doesn't exhibit the behavior. only happens with slim select. very weird.
i would have but typescript puts up too much of a burden because it doesn't even accept a string-id as part of a passed option. |
Beta Was this translation helpful? Give feedback.
-
This is all because your passing in a number and not a string? Also your typescript comment makes no sense. |
Beta Was this translation helpful? Give feedback.
-
yes. have a look at this fiddle: https://jsfiddle.net/glaszig/ojdhsmvw/
describe('events', () => {
test('dispatch change event', async () => {
document.body.innerHTML = `<select id="test"></select>`
let selectElement = document.getElementById('test') as HTMLSelectElement
let select = new Select(selectElement)
let store = new Store('single', [
{
id: 1,
value: '1',
text: 'One',
selected: false
},
{
id: 2,
value: '2',
text: 'Two',
selected: false
}
])
let data = store.getData()
select.updateOptions(data)
var eventCount = 0
selectElement.addEventListener("change", () => eventCount += 1)
selectElement.dispatchEvent(new Event("change", { bubbles: true }))
expect(eventCount).toEqual(1)
})
})
|
Beta Was this translation helpful? Give feedback.
-
came across this after updating from version 1.27 to version 2.9 but i remember i encountered this issue in an earlier 2.x version as well but gave up. now i spent an entire day to discover the following in awe:
when you feed slim select options with id properties whose value is not a string, i.e. an integer, it will cause the browser to emit 2 change events.
see this more elaborate fiddle.
i tried to fix this in the source by casting to string but i don't get along with typescript.
solution
make sure your id properties are strings.
Beta Was this translation helpful? Give feedback.
All reactions