I am using the Bootstrap Datepicker (found here: http://mgcrea.github.io/angular-strap/#/datepicker) on an input field. By default, the datepicker allows a date to be entered. If it is valid, then it sets the date. Otherwise, it sets the date to the current date.
I wrote a directive that uses a regex to only characters for a date to be input.:
maskModelCtrl.$parsers.push(function(inputValue) {
var val = maskRenderLogic(inputValue, mask, maxVal);
setAndRender(maskModelCtrl, val);
return maskReturnLogic(val);
});
And I wrote a directive to standardize the input field for the datepicker with a template:
angular.module('form.validation').directive('dateMask', ['$parse', function($parse) {
return {
restrict: 'E',
scope: {
date: '='
},
template: '<input ng-model="date" regex-mask="[^0-9 /]" max-length="10" bs-datepicker data-date-format="mm/dd/yyyy" placeholder="mm/dd/yyyy" >',
replace: true
};
}]);
The problem is, the datepicker translates any keyboard input or date selections to the current date. (See plnkr: http://plnkr.co/edit/oCZnq0UOmaxC83Rv7YSs?p=preview) I don't think that these directives should be incompatible with each other.