I have a directive to format the date. It should return the error information like ng-invalid when the format of input goes wrong. Now it can set ng-invalide in this case, but it also set ng-valid-parse if the format of input is wrong. In my opinion, as the format goes wrong, it is not valide.
So here comes my question : how the ng-valid-parse is set ?
myDirectives.directive('myDateFormat', function ($window) {
'use strict';
return {
require: 'ngModel',
restrict: 'A',
link: function (scope, elm, attrs, ctrl) {
// other codes ...
ctrl.$parsers.unshift(function (viewValue) {
var date = moment(viewValue, dateFormat);
if(date && date.isValid()){
return date.toDate();
}else{
ctrl.$setValidity('myDateFormat', false);
return ""; // or it should return false here?
}
});
}
};
});
Thanks !