[Input Masks Library] backspace or delete won't trigger InputMask_OnChange with single digit
input-masks-mobile
Reactive icon
Forge component by Labs
Application Type
Reactive

When the loaded value is a single digit (1 - 9) and I delete the value without first changing it, using backspace or delete the InputMask_OnChange won't trigger.

The visible value is changed to 0, but when I inspect the HTML Value remains the same and when I save the value it isn't changed.

But when I change the value once and then delete the value everything works fine and the 0 value is saved.


Hopefully someone has a solution for this.


Kind regards,


Joris

I had the same issue and I fixed it by setting "0" as default value in the maskedvalue variable inside the inputmasklibrary 

Tnx that solved the problem.

Hey guys, I know this post is solved but for those of you who have this problem with the currency input mask and cannot solve it with Nick's suggestion(happened to me), I wrote a small jQuery script to work this issue around. I placed the JS node inside the OnRender lifecycle hook:

$('.your-input-class.masked-value').one('keyup', function(e){

    if(e.keyCode === 8 || e.keyCode === 46) {

        if($(this).val() === 0 || $(this).val() === undefined || $(this).val() === "") {

            // Set input val attr

            $(this).attr('value', "0");

            $(this).val('$0.00');

            

            // Set hidden input val attr

            var hiddenInput = $(this).closest('.currency-mask').find('.vanilla-input').find('.your-input-class');

            hiddenInput.attr('value', "0");

            hiddenInput.val(0);

        }

    }

});


What this does is detecting an input clear by backspacing or deleting the input value. This solution is fairly new so it might need some tweeks on your side. Also make sure that you call your OnChange action at the end of the keyup event.


Cheers,
Fred.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.