RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.37k stars 2.17k forks source link

Change event not being called properly within a setValue event triggered by focusout #2718

Open dakota-kallas opened 1 year ago

dakota-kallas commented 1 year ago

Bug Description

In jQuery, if you attached a focusout event to an input and within that event call to set the value with .val(value) on the element, a change event is automatically triggered. However, if you do that same thing with a masked input field the change event is not fired.

This appears to be caused because the inputmask plugin updates a value labeled inputmask.undoValue when setValue is called. That same inputmask.undoValue is what allows the change event to trigger if it differs from the current value. This is taking place within the function applyInputValue() defined in the fileinputHandling.js, inputmask.undoValue = inputmask._valueGet(true); https://github.com/RobinHerbots/Inputmask/blob/a7a850ac30fe668744aa5dba49549fd697892286/lib/inputHandling.js#L26 If that line of code is commented out, the change event is triggered as expected. That is because it is now allowed to pass the validation in the blurEvent defined in file eventhandlers.js, if (inputmask.undoValue !== nptValue). This functionality is not allowing me to use the mask properly. Using the blur event instead of the focusout does trigger the change event, but I cannot us the blur event in my solution. This behavior is different from how jQuery functions with events and should require a bug fix for the plugin to handle this properly.

CodePen Link

https://codepen.io/dakota-kallas/pen/jOQMaPQ?editors=1010

System Information