Default value with imaskjs

Asked

Viewed 38 times

0

I created a mask using imaskjs for monetary value in an HTML input:

var element = document.getElementById("txtTeste");

var maskOptions = {
    mask: Number,
    scale: 2,
    thousandsSeparator: ".",
    padFractionalZeros: true,
    normalizeZeros: true,
    radix: ",",
    mapToRadix: ["."],
    min: -999999999.99,
    max: 999999999.99
};

var mask = IMask(element, maskOptions);

Has some default value property for when the user enters a null value?

  • Place a check when leaving the field... Let’s say that the user entered the field and did not put anything, when leaving the field (focusout()) you put its value "default"

  • @Azzi this is the way I do today, but if this library had another way, it would be easier.

1 answer

1

I managed to pass a function to the key "commit":

var maskOptions = {
    mask: Number,
    scale: 2,
    thousandsSeparator: ".",
    padFractionalZeros: true,
    normalizeZeros: true,
    radix: ",",
    mapToRadix: ["."],
    min: -999999999.99,
    max: 999999999.99,
    commit: function (value, masked) {
        if (trim(value + "") == "") {
            masked._value = "0,00";
        }
    }
};
  • Perfect, now it’s gone!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.