cleave.js icon indicating copy to clipboard operation
cleave.js copied to clipboard

Object.setRawValue get error

Open zon999 opened this issue 10 years ago • 6 comments

I use angularjs and get error:

angular.min.js?d=1060806703:114 TypeError: Cannot read property 'toString' of undefined at Object.setRawValue (cleave-angular.min.js?d=403551635:8) at Array. (cleave-angular.min.js?d=403551635:8) at angular.min.js?d=1060806703:277 at m.$digest (angular.min.js?d=1060806703:138) at m.$apply (angular.min.js?d=1060806703:141) at g (angular.min.js?d=1060806703:94) at t (angular.min.js?d=1060806703:98) at XMLHttpRequest.u.onload (angular.min.js?d=1060806703:99)

Could you tell me to fix it?

zon999 avatar Sep 27 '16 07:09 zon999

Can you please share more details about how you use it, any jsfiddle file?

nosir avatar Sep 30 '16 09:09 nosir

https://jsfiddle.net/o7nejrsg/

zon999 avatar Sep 30 '16 10:09 zon999

This seems to happen on initial load when the model property isn't defined in the controller yet. The Angular directive will kick off the formatter and pass undefined to setRawValue. Can be easily fixed by changing

$scope.cleave.setRawValue(val);

into

$scope.cleave.setRawValue(val ? val : '');

markleusink avatar Sep 30 '16 10:09 markleusink

@markleusink Thanks a lot, I will push a fix to include the check in the method.

nosir avatar Sep 30 '16 10:09 nosir

@markleusink Oh, just saw your PR, will merge later. Cheers

nosir avatar Sep 30 '16 10:09 nosir

Thanks very much

zon999 avatar Sep 30 '16 10:09 zon999