RobinHerbots/Inputmask

TypeError: Cannot read properties of null (reading 'charAt') at m.onBeforeMask

sinhnv1991 opened this issue · 3 comments

Please add new line e = e === null ? "" : e; on file inputmask.js at function onBeforeMask: function(e, t) {...
line 1812, because if value to input from database is null, null is not string can't reading charAt
onBeforeMask: function(e, t) {
var n = t.radixPoint || ",";
//please add line
e = e === null ? "" : e;//check only null because keep 0 value display to input
}
example mask currency will error

  • vesion: lasted

You shouldn't set values to null in any input or textarea. If you are receiving a null value from an external source, it's your job to convert it to a proper input element representation, e.g. converting null to an empty string or 0.

I usually check the initial value of my components which use Inputmask if it's valid. If it's not valid (empty string, null, undefined), I would set it to a default value like 0 or to a minimum value.

@sinhnv1991, @Techn1c4l ,

I can agree with what @Techn1c4l says, but on the other hand should the mask not fail if some faulty value is passed, but it should just ignore it.