maxmarcon / live_select

Dynamic (multi)selection field for LiveView
https://hex.pm/packages/live_select
Apache License 2.0
186 stars 35 forks source link

replaced input[class=single-mode] with input.single-mode #41

Closed ivanminutillo closed 1 year ago

ivanminutillo commented 1 year ago

Hello, I am experiencing this very weird error since some time now using live_select

live_select.min.js:24 Uncaught TypeError: Cannot read properties of null (reading 'dispatchEvent')
    at ViewHook.inputEvent (live_select.min.js:24:40)
    at live_select.min.js:24:526
    at callbackRef (view_hook.js:43:65)
    at Object.dispatchEvent (dom.js:335:12)
    at LiveSocket.dispatchEvent (live_socket.js:737:9)
    at live_socket.js:741:47
    at Array.forEach (<anonymous>)
    at LiveSocket.dispatchEvents (live_socket.js:741:12)
    at View.update (view.js:527:21)
    at view.js:600:68

After some debugging I found that this line https://github.com/maxmarcon/live_select/blob/main/assets/js/live_select.js#L81 don't return the input node (when single-mode is selected). But if I replace input[class=single-mode] with input.single-mode the issue is solved. I'm aware that using the attr syntax with classes is risky (eg. it does work only if the order of the classes differs and it's less performant than using class-based selectors...

maxmarcon commented 1 year ago

Thank you for spotting and fixing this! No idea what I was thinking when I wrote that nonsense. I must have been tired :)