I have a question concerning the consistency / rel...
# javascript
c
I have a question concerning the consistency / reliability of DOM API's event types and different browsers. Imagine a simple HTML
input
element with a
datalist
attached as kind of "type ahead" component. In order to add some logic within an UI framework (I work on the fritz2 framework FYI), one need to register a listener on specific events of course. For this use case I consider the
input
event as the best fitting one. According to MDN the event has the interface
InputEvent
. But this seems to be false for some circumstances and browsers: If one selects a proposal from the datalist at least in Chrome and Safari Browsers (mobile too) instead a simple
Event
event is fired! Here is a small HTML file to make this visible:
Copy code
<html>

<body>
    <input id="myinput" type="text" list="mydata">
    <datalist id="mydata">
        <option value="Kotlin"></option>
        <option value="Scala"></option>
        <option value="Java"></option>
        <option value="Python"></option>
        <option value="Commodore Basic V2"></option>
    </datalist>

    <script>
        document.getElementById("myinput").oninput = function(e) {
            console.log(Object.getPrototypeOf(e))
        }
    </script>
</body>

</html>
In Firefox one always get the
InputEvent
no matter if just typing a letter or selecting a proposal from the list. In Chrome or Safari this differs; when selecting from the list, only
Event
is fired. This leads to problems in Kotlin of course if one tries to cast this depending on the event name, as
input
does not always return the same type as shown above. How to deal with this situation? Is there some kind of specification that reveals the different events for the different browsers? What's the reason for browsers to offer different event types for the same event key? (If someone has interest in the framework specific impacts, have a look at the appropriate PR on github, which will lead to the relevant code sections.)
😯 1
Ok, I have meanwhile found a table within the standard that shows the relation between event (string) and interface type: https://html.spec.whatwg.org/multipage/indices.html#events-2 But it is denoted as "non-normative"... great wording for a "standard" 🤪 Also I am wondering why some events (like
close
or
error
for example) might freely decide which event interface they use... not pleasent for static typed languages! (At least without real sum types!!! We need those in Kotlin 😉)
i
@Christian Hausknecht Could you, please, create a ticket with this feature request and describe it in there, so this request won’t be lost in this channel? kotl.in/issue
c
I am not sure whether this is an issue at all! It is more a browser / HTML issue... Or do you mean the sum types? This wont need an issue imho, as you have proposed this for future features within your feature survey.
👍 1