Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery 'input' event receiving unexpected value #766

Open
luis-fss opened this issue Feb 27, 2021 · 0 comments
Open

jQuery 'input' event receiving unexpected value #766

luis-fss opened this issue Feb 27, 2021 · 0 comments

Comments

@luis-fss
Copy link

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant