If 'applyMask()' is called before setting up the 'input' event, pressing any letter key will hit the event, but if 'applyMask()' is called after setting up the 'input' event, pressing any letter key will not hit the event.
jQuery('.btn').on('click', function(){
jQuery('#MyField').unmask().mask('#.##0,00', { reverse: true })
})
function applyMask() {
jQuery('#MyField').mask('#.##0,00', { reverse: true })
}
// applyMask() // here, before the input event, this function will behave nicely
jQuery('#MyField').on('input', function() {
let val = jQuery(this).val()
jQuery('.change-event-values').prepend('<p>'+ val +'</p>')
})
applyMask() // Here, after the input event, any letter will pass through the event.
Device
Windows 10
Browser (and version)
Google Chrome v88.0.4324.190 64 bits
Functional
jsfiddle
exemplifying the problem:https://jsfiddle.net/Lukkian/tgqjof23/4/
Describe the problem:
If 'applyMask()' is called before setting up the 'input' event, pressing any letter key will hit the event, but if 'applyMask()' is called after setting up the 'input' event, pressing any letter key will not hit the event.