I know there are a lot of similar questions, but I haven't found exactly my case.
Using vanilla JS there is an input control in which a user types something. A date as an example (but could be a phone number or anything else with a fixed format). The input data is validated using element's change event. So when a user finishes (by pressing enter or leaving the control, or submitting, etc.) a validation occurs and if something is wrong an error message is shown.
For a good UX the validation error is cleared once a user starts typing again (i.e. tries to edit the error). This is needed so the user is not confused that data is 'invalid' while he types it because he hasn't finished yet. And when he does finish typing, data is revalidated again. We are not doing real-time validation since it looks confusing ("am I typing already invalid data??").
For example, typing unfinished date like 12.12 (without a year) will result in validation error. And when a user starts typing again, the error is cleared until user is finished.
Now consider a case:
- user types
12.12; - presses
enter; - validation starts and results in an error;
- users clears input and types
12.12again; - presses
enter; - no validation occurs, since
inputelement sees no changes in it's value, hence nochangeevent.
So the question is, how to make input element believe that data is actually changed so the event is fired again when user finishes editing?
Not sure if emulating change event is a good idea (e.g. by dispatching it manually in blur or keypress=enter or anything similar).
I'm looking for something like an 'optimization' flag for input that when disabled will force it to dispatch change event regardless of actually changed value. Or something like invalidateElementValue that could be called inside element's input event.
changeevent is a good idea": Why use thechangeevent in the first place? Based on your description, it seems like it's not the right choice. Are you sure about how it works and which conditions you want to accept as "finalization" states?input-event. Regarding validation, thechange-event almost always is of no good use.bluris not triggered when a user pressesenterto finish editing without changing focus.changeis triggered when a user actually finishes editing (changing focus, pressing enter, using auto-fill, etc.).