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

Callback making On-the-fly mask change doesnt' work #755

Closed KelvinRonaldo closed 3 years ago

KelvinRonaldo commented 3 years ago

I'm trying to make an On-the-fly mask change creating an CPF/CNPJ mask:

JavaScript

$(document).ready(function(){
    var cpfCnpjMask = {
        onKeyPress: function(cpfCnpj, e, field, options) {
          var masks = ['000.000.000-00', '00.000.000/0000-00'];
          var mask = (cpfCnpj.length > 11) ? masks[1] : masks[0];
          $('.cpf-cnpj-mask').mask(mask, cpf-cnpj-mask);
            }
        };
    $('.cpf-cnpj-mask').mask('000.000.000-00', cpfCnpjMask);
}

HTML

<label>Documento</label>
<input type="text" class="form-control cpf-cnpj-mask" name="document">

I'm using laravel, so this html code is in an .blade.php file. The other masks without callback functions work normally, but with callback doesn't have any effect.