Guest User

Untitled

a guest
May 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <input type="text" datepicker-popup="dd.mm.yyyy" ng-model="dt" datepicker-options="dateOptions" ng-required="true">
  2.  
  3. evsDirectives.directive('dateParser', function () {
  4. return {
  5. restrict: 'A',
  6. require: 'ngModel',
  7. link: function (scope, element, attrs, ctrl) {
  8. if (!ctrl)
  9. return;
  10.  
  11. ctrl.$parsers.unshift(function (data) {
  12. // convert data from view format to model format
  13. return this.parseEuropeanShortDate(data);
  14. });
  15. }
  16. };
  17.  
  18. //parses a date in dd/MM/yyyy format
  19. //returns the input value if not a valid date
  20. parseEuropeanShortDate: function (d) {
  21. if (this.isDate(d)) {
  22. return d;
  23. }
  24. else {
  25. var fragments = d.split('/');
  26. var result = new Date(Date.UTC(fragments[2], fragments[1] - 1, fragments[0])); // converted
  27. return (this.isValidDate(result)) ? result : d;
  28. }
  29. }
  30.  
  31. });
  32.  
  33. <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