ngMask icon indicating copy to clipboard operation
ngMask copied to clipboard

error with input type number

Open lucaszadok opened this issue 9 years ago • 5 comments

When I use the mask it returns an error (below), I guess you are expecting a string. TypeError: a.split is not a function

lucaszadok avatar May 15 '15 23:05 lucaszadok

I was just tracking down this error on my own implemetation.

The problem is in removeDivisors function in ngMask.js starting at line 395 https://github.com/candreoliveira/ngMask/blob/d33f52913deeccf3c039e7f16ada9482a9a7c442/dist/ngMask.js

Specifically, return value.replace(regex, ''); on line 412. Numbers don't have the replace function - only strings.

gpit2286 avatar May 26 '15 02:05 gpit2286

any solution?

emretoprak avatar Jul 22 '15 12:07 emretoprak

So looking at this, I think we're looking at two different places with the same problem.

https://github.com/candreoliveira/ngMask/blob/master/dist/ngMask.js#L76

With this line, it is doing an automatic type cast to whatever the value is in the textbox. It would probably be better to do something like this:

if (typeof value == 'undefined') {
  value = '';
} else {
  //Cast to string in order to use String/RegExp functions
  value = '' + value;
}

I'm not currently using this anymore or I would just drop it into my application. Try it and see if it works. If it does you or I can submit a pull request.

gpit2286 avatar Jul 25 '15 18:07 gpit2286

@gpit2286 - your fix worked for me, thank you. Is it possible for you to submit it as a PR? :)

maccath avatar Aug 11 '15 08:08 maccath

I had this same issue. Switched the type from number to text worked for me.

n8yeung avatar Nov 24 '15 21:11 n8yeung