Text-mask: vanilla import error

Created on 31 Aug 2016  路  5Comments  路  Source: text-mask/text-mask

i'm install plugin

import maskInput from './vendor/vanillaTextMask'
console.log(maskInput);

_console say's:_
function o(e){var r=e.inputElement,t=(0,a["default"])(e),n=function(e){var r=e.target.value;return t.update(r)};return r.addEventListener("input",n),{textMaskInputElement:t,destroy:function(){r.removeEventListener("input",n)}}}

and init it

maskInput({ inputElement: $userPhone, mask: mask });

_console say's:_
TypeError: r.addEventListener is not a function. (In 'r.addEventListener("input",n)', 'r.addEventListener' is undefined)

question vanilla

Most helpful comment

For anyone who encounter the same TypeError - make sure that inputElement is truly an element, not NodeList. For example:

maskInput({
  inputElement: document.querySelectorAll(foo),
  mask: date
});

will throw TypeError: r.addEventListener is not a function. (In 'r.addEventListener("input",n)', 'r.addEventListener' is undefined) cause r is nodeList

so you should use (ES6)

for (let input of document.querySelectorAll(foo)) {
maskInput({
  inputElement: input,
  mask: date
});
vanillaTextMask.maskInput({
  inputElement: input,
  mask: date
});
}

All 5 comments

Can you show a more complete setup, perhaps create on minimum project on GitHub showing your setup and share a link to that? I can't really tell what's going on just by what you've posted above.

In the example (for vanilla) notice masker.maskInput is not called, but maskInput() is. So for anyone else, this should work:

import maskInput from 'vanilla-text-mask'

//...

maskInput({
  inputElement: inputElement
  //options etc...
})

I'll close this issue for now, but please feel free to continue to post here when there's more information.

Hello!
I repeat this problem with vanilla-text-mask.
My call:

var myInput = document.querySelectorAll('input[data-mask="date"]');

console.log( myInput );

var date = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];

var maskedInputController = vanillaTextMask.maskInput({
  inputElement: myInput,
  mask: date
});

in console:
Uncaught TypeError: t.addEventListener is not a function

I dont use webpack and ES6. File js added from./node_modules/vanilla-text-mask/dist/vanillaTextMask.js`

Thank`s )

For anyone who encounter the same TypeError - make sure that inputElement is truly an element, not NodeList. For example:

maskInput({
  inputElement: document.querySelectorAll(foo),
  mask: date
});

will throw TypeError: r.addEventListener is not a function. (In 'r.addEventListener("input",n)', 'r.addEventListener' is undefined) cause r is nodeList

so you should use (ES6)

for (let input of document.querySelectorAll(foo)) {
maskInput({
  inputElement: input,
  mask: date
});
vanillaTextMask.maskInput({
  inputElement: input,
  mask: date
});
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

caub picture caub  路  4Comments

skube picture skube  路  3Comments

badre429 picture badre429  路  3Comments

jvbianchi picture jvbianchi  路  5Comments

Sn3b picture Sn3b  路  6Comments