Skip to content

A way to determine what the value of an input will be if beforeinput is not prevented #289

@devongovett

Description

@devongovett

It would be very useful to have a way to determine what the value of an <input> element will be if beforeinput is not prevented. For example, when implementing validation of text entry (e.g. a number field, telephone field, credit card number, etc.), the beforeinput event can be used to cancel invalid characters from being typed.

However, especially with deletion inputTypes, it can be challenging to get the full input value that would be committed after the beforeinput event. This is necessary in some cases to prevent deletion of certain parts of the input value. We can look at the selection and attempt to modify the existing value accordingly but this has many pitfalls, especially to do with unicode. For example, deletion by word or sentence is tricky to handle correctly. Plus, we shouldn't need to reinvent the code that the browser already has to do this.

Perhaps the InputEvent could have a property that indicates what the value will be after it is applied in addition to the data that is inserted? Or maybe that belongs on the HTMLInputElement specifically, since I could see this being challenging to support for contenteditable?

This issue is mainly a starting point for a conversation about this usecase, and I'm entirely open to any and all suggestions. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions