Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Implement ngChange attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmdev committed Oct 29, 2018
1 parent e29f737 commit 977cbf3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngComboDatePicker",
"version": "1.5.1",
"version": "1.6.0",
"authors": [
"jfmdev <jfmdev@outlook.com>"
],
Expand Down
25 changes: 23 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h3>Disable all</h3>
<p>Choose a date: <ng-combo-date-picker ng-model="disableBoxes1" ng-disabled="disableFlag"></ng-combo-date-picker></p>
<p><input type="checkbox" ng-model="disableFlag"/> Disable combo boxes</p>
</div>

<h3>Disable one by one</h3>

<div ng-init="disableFlags = [false, false, false]">
Expand All @@ -263,7 +263,28 @@ <h3>Disable one by one</h3>
<p><input type="checkbox" ng-model="disableFlags[1]"/> Disable month</p>
<p><input type="checkbox" ng-model="disableFlags[2]"/> Disable year</p>
</div>


<h2>Change event</h2>

<script type="text/javascript">
app.controller('ngChangeCtrl', function ($scope) {
$scope.changeDate = new Date();

$scope.lastChange = null;
$scope.dateChanged = function() {
$scope.lastChange = new Date();
};
});
</script>
<div ng-controller="ngChangeCtrl">
<p>Choose a date: <ng-combo-date-picker ng-model="changeDate" ng-change="dateChanged"></ng-combo-date-picker></p>
<p>
The date was
<span ng-if="!lastChange">never changed</span>
<span ng-if="lastChange"> last changed on {{ lastChange | date:'medium' }}</span>
</p>
</div>

</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-combo-date-picker",
"version": "1.5.1",
"version": "1.6.0",
"description": "An Angular directive to select dates using combo boxes",
"main": "source/ngComboDatePicker.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions source/ngComboDatePicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ngComboDatePicker v1.5.1
* ngComboDatePicker v1.6.0
* http://github.com/jfmdev/ngComboDatePicker
* «Copyright 2015 Jose F. Maldonado»
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand Down Expand Up @@ -84,7 +84,8 @@ angular.module("ngComboDatePicker", [])
ngYearOrder: '@',
ngPlaceholder: '@',
ngPlaceholderEnabled: '@',
ngRequired: '@'
ngRequired: '@',
ngChange: '='
},
require: 'ngModel',
controller: ['$scope', function($scope) {
Expand Down Expand Up @@ -217,6 +218,13 @@ angular.module("ngComboDatePicker", [])
$scope.dates.push({value:i, name:i});
}
};

// Listen on changes on ngModel for trigger ngChange event.
$scope.$watch('ngModel', function(newValue, oldValue) {
if(newValue !== oldValue && $scope.ngChange) {
$scope.ngChange(newValue, oldValue);
}
});
} ],

link: function(scope, element, attrs, ngModelCtrl) {
Expand Down
4 changes: 2 additions & 2 deletions source/ngComboDatePicker.min.js

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

0 comments on commit 977cbf3

Please sign in to comment.