Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input type="text" datepicker-popup="dd.mm.yyyy" ng-model="dt" datepicker-options="dateOptions" ng-required="true">
- evsDirectives.directive('dateParser', function () {
- return {
- restrict: 'A',
- require: 'ngModel',
- link: function (scope, element, attrs, ctrl) {
- if (!ctrl)
- return;
- ctrl.$parsers.unshift(function (data) {
- // convert data from view format to model format
- return this.parseEuropeanShortDate(data);
- });
- }
- };
- //parses a date in dd/MM/yyyy format
- //returns the input value if not a valid date
- parseEuropeanShortDate: function (d) {
- if (this.isDate(d)) {
- return d;
- }
- else {
- var fragments = d.split('/');
- var result = new Date(Date.UTC(fragments[2], fragments[1] - 1, fragments[0])); // converted
- return (this.isValidDate(result)) ? result : d;
- }
- }
- });
- <input type="text" datepicker-popup="dd.mm.yyyy" ng-model="dt" datepicker-options="dateOptions" ng-required="true" date-parser>
Add Comment
Please, Sign In to add comment