angular-payments icon indicating copy to clipboard operation
angular-payments copied to clipboard

payments-format="expiry" Invalid Date issue

Open kevinwritescode opened this issue 10 years ago • 3 comments

I'm noticing when I first load a form with payments-format="expiry" that I'm getting an "Invalid Date" javascript error. I tracked it down to the function call for _getFormattedExpiry.

var _getFormattedExpiry = function(value) { if(value !== null) { var obj = Common.parseExpiry(value); var expiry = new Date(obj.year, obj.month-1); return $filter('date')(expiry, 'MM / yyyy'); } return null; };

The problem is that value being passed in is undefined, not null. I was able to fix the issue in my code by setting the ng-model value to null once I start the controller, but I wasn't sure if it'd be safer to check if null or undefined?

kevinwritescode avatar Jan 27 '16 20:01 kevinwritescode

This error appeared for me when I last time did a major update to packages in our project. Not sure which package had influence on revealing it, though.

I came up with the same workaround to this issue (initialising my model with null) and it works fine.

piotrd avatar Jan 28 '16 09:01 piotrd

Init scope.expiry or whatever the ngModel is for the expiration field to null fixes validation issue.

Thank you for the share

mr-White avatar May 09 '16 21:05 mr-White

same happen to me, setting ngModel to null fix the issue.

abdou-ghonim avatar Feb 04 '20 23:02 abdou-ghonim