RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

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

Closed sinhnv1991 closed 4 months ago

sinhnv1991 commented 4 months ago

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

Techn1c4l commented 4 months ago

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.

RobinHerbots commented 4 months ago

@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.

sinhnv1991 commented 4 months ago

I don't agree because not good performance on server convert null to empty string, example more data of key in php array is null, or array more nested key data is null display to more input, we will format it on server not good

On Tue, May 14, 2024 at 1:52 PM Robin Herbots @.***> wrote:

@sinhnv1991 https://github.com/sinhnv1991, @Techn1c4l https://github.com/Techn1c4l ,

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

— Reply to this email directly, view it on GitHub https://github.com/RobinHerbots/Inputmask/issues/2789#issuecomment-2109415230, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWDJR3VJWUJKNGIXIILS3TTZCGYB7AVCNFSM6AAAAABHSF3W6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBZGQYTKMRTGA . You are receiving this because you were mentioned.Message ID: @.***>