Inputmask icon indicating copy to clipboard operation
Inputmask copied to clipboard

Cannot read properties of null (reading 'inputmask')

Open antman3351 opened this issue 9 months ago • 0 comments

Hi,

The FormData hook calls getElementById() using the input name as the id https://github.com/RobinHerbots/Inputmask/blob/477f8742d0edb0b916c30d5fb8cf50e83fbcf6e5/lib/global/FormData.js#L10C1-L11C1

I think const element = document.getElementById(entry.value[0]); should be const element = form[ entry.value[0] ] and also a check that element isn't undefined might be a good idea e.g. if (element !== undefined && element.inputmask !== undefined)

With the folowing snippet you can see that the key is the name

<form id="test">
    <input name="test1" id="testA">
    <input name="test2">
    <input id="testB">
</form>

<script>
    const form = document.forms.test;
    const formData = new FormData( form );
    const entries = formData.entries();
    let entry;
    while ((entry = entries.next()).done === false) {
       console.log( entry );
       console.log( form[ entry.value[0] ] );
    }
</script>
  • OS: Windows 10/11
  • Browser: Chrome / FireFox
  • Inputmask version: 5.0.10-beta.37

[Edit 18.03.2025 changed null check with undefined]

antman3351 avatar Mar 17 '25 13:03 antman3351