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

error after cleaning input field #723

Closed rizkymeiputra closed 5 years ago

rizkymeiputra commented 5 years ago

Hi, I get this error when I inputted 10000, then I press reset button, after that I try to input 10000 again but its not work, its only work when 1000 and 100000, but its also work on 10001

Here's the fiddle https://jsfiddle.net/dgtpvwy3/1/

Thanks

igorescobar commented 5 years ago

@rizkymeiputra I couldn't reproduce the issue. What device are you on?

igorescobar commented 5 years ago

If you could make a screen recording would be good.

rizkymeiputra commented 5 years ago

@igorescobar Sure, here https://www.dropbox.com/s/qdhpsy9m7y6zzlf/AwesomeScreenshot-2019-8-23-1566551314251.webm?dl=0

I use Chrome Version 75.0.3770.100 (Official Build) (64-bit) run on Ubuntu 18

igorescobar commented 5 years ago

@rizkymeiputra Since you are pragmatically changing the input without using plugin's core methods the plugin can naturally lose the track of the previous value etc. Instead, what you can do is:

$(document).ready(function(){
    $('.input-mask').mask('000.000.000', { reverse: true });

    $('.input-mask').on('input', () => {
        $('.unmasked').val($('.input-mask').cleanVal());
    });

    $('.btn-reset').click(function(){
        $('.input-mask, .unmasked').val('');
    });
})

Just use the native input event you don't need the internal plugin event to do that.

Hope it heps.

rizkymeiputra commented 5 years ago

@igorescobar Oh, great! It's working well! Thank you so much...