Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
* Changes broke unit test. Reverting to previous version.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnasir committed Sep 24, 2014
1 parent 44d27aa commit 951135b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions dateparser.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@ angular.module('dateParserDirective', ['dateParser'])
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
var dateFormat;
// If a new format is provided, update the view by rendering the model again.

attrs.$observe('dateParser', function(value) {
dateFormat = value;
// Leave the actual rendering to other directives. Angular provides these by default for <input>, <textarea> and <select>
if (angular.isFunction(ngModel.$render))
ngModel.$render();
ngModel.$render();
});

// Parse the input value to a date
ngModel.$parsers.push(function(viewValue) {
var parseDate = function(viewValue) {
var date = $dateParser(viewValue, dateFormat);

if (isNaN(date)) {
if(isNaN(date)) {
ngModel.$setValidity('date', false);
} else {
ngModel.$setValidity('date', true);
}

return date;
});
};
ngModel.$parsers.unshift(parseDate);

ngModel.$render = function() {
var date = ngModel.$modelValue ? dateFilter(ngModel.$modelValue, dateFormat) : '';
element.val(date);
scope.ngModel = ngModel.$modelValue;
};

// Format the new model value before it is displayed in the editor
ngModel.$formatters.push(function(modelValue) {
return modelValue ? dateFilter(modelValue, dateFormat) : '';
element.bind('input change keyup', function() {
scope.$apply(function() {
scope.ngModel = ngModel.$modelValue;
});
});
}
};
Expand Down

0 comments on commit 951135b

Please sign in to comment.