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

Commit

Permalink
Merge pull request #27 from dnasir/dev
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
dnasir committed Nov 23, 2014
2 parents 61e0481 + 4dd7ef7 commit e68810a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-dateParser",
"version": "1.0.11",
"version": "1.0.12",
"homepage": "https://github.com/dnasir/angular-dateParser",
"authors": [
"Dzulqarnain Nasir"
Expand Down
19 changes: 13 additions & 6 deletions dateparser.directive.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* DateParser directive
*
* Use this directive in form fields to implement the dateParser functionality.
*/

angular.module('dateParser')
.directive('dateParser', ['dateFilter', '$dateParser', function(dateFilter, $dateParser) {

Expand All @@ -16,12 +22,9 @@ angular.module('dateParser')

ngModel.$parsers.unshift(function(viewValue) {
var date = $dateParser(viewValue, dateFormat);

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

// Set validity when view value changes
ngModel.$setValidity('date', angular.isDate(date));

return date;
});
Expand All @@ -34,6 +37,10 @@ angular.module('dateParser')

// Format the new model value before it is displayed in the editor
ngModel.$formatters.push(function(modelValue) {

// Set validity when model value changes
ngModel.$setValidity('date', angular.isDate(modelValue));

return modelValue ? dateFilter(modelValue, dateFormat) : '';
});
}
Expand Down
7 changes: 2 additions & 5 deletions demo.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html ng-app="dateParserDirective">
<html ng-app="dateParser">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Expand Down Expand Up @@ -194,14 +194,11 @@ <h6>Code</h6>
</footer>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="dateparser.js"></script>
<script src="dateparser.directive.js"></script>
<script src="dist/angular-dateparser.min.js"></script>
<script>
function controller($scope) {
$scope.format = 'dd.MM.yyyy';
$scope.date = new Date();


}
</script>

Expand Down
9 changes: 3 additions & 6 deletions dist/angular-dateparser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* angular-dateParser 1.0.11
* angular-dateParser 1.0.12
* https://github.com/dnasir/angular-dateParser
* Copyright 2014, Dzulqarnain Nasir
* Licensed under: MIT (http://www.opensource.org/licenses/MIT)
Expand Down Expand Up @@ -243,18 +243,15 @@
});
ngModel.$parsers.unshift(function(viewValue) {
var date = $dateParser(viewValue, dateFormat);
if (isNaN(date)) {
ngModel.$setValidity("date", false);
} else {
ngModel.$setValidity("date", true);
}
ngModel.$setValidity("date", angular.isDate(date));
return date;
});
ngModel.$render = function() {
element.val(ngModel.$modelValue ? dateFilter(ngModel.$modelValue, dateFormat) : undefined);
scope.ngModel = ngModel.$modelValue;
};
ngModel.$formatters.push(function(modelValue) {
ngModel.$setValidity("date", angular.isDate(modelValue));
return modelValue ? dateFilter(modelValue, dateFormat) : "";
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-dateparser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e68810a

Please sign in to comment.