igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.77k stars 1.42k forks source link

Can't catch enter key 13 #750

Closed s1monj closed 4 years ago

s1monj commented 4 years ago

great plugin, thanks for your work

I want to trigger a function when the enter key is pressed - ie the user types a number of unknown length (using '0#' mask) and then hits the enter key to submit

I tried adding 13 to the byPassKeys, but it still prevents the onKeyPress from firing

http://jsfiddle.net/simonlj/jcuh4ev7/14/

igorescobar commented 4 years ago

Hey @s1monj

The plugin's onKeyPress behaviour has a peculiar behaviour attached to it. If you want you can always use the native events from jQuery.

$('.cep_with_callback').on('keypress', function(e) {
  const cep = e.target.value;
  console.log('a key was pressed!:', cep);
   if (event.which == 13) {
        console.log('enter key is pressed, ', cep);
    }
})
 .mask('0#');
s1monj commented 4 years ago

great thanks that did the trick