candreoliveira / ngMask

Best Angular mask alternative! No jQuery, pure JS. About ~6kb!
http://candreoliveira.github.io/#/ngMask
ISC License
419 stars 171 forks source link

error with input type number #29

Open lucaszadok opened 9 years ago

lucaszadok commented 9 years ago

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

gpit2286 commented 9 years ago

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.

emretoprak commented 9 years ago

any solution?

gpit2286 commented 9 years ago

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.

maccath commented 9 years ago

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

n8yeung commented 8 years ago

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