Last active
December 26, 2015 10:09
-
-
Save dbajpeyi/7134637 to your computer and use it in GitHub Desktop.
A simple angularjs directive for bootstrap datepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var appDirective = angular.module('directives',[]); | |
appDirective.directive('datePicker', function() { | |
return { | |
restrict: 'E', | |
require: ['ngModel'], | |
scope: { | |
ngModel: '=' | |
}, | |
replace: true, | |
template: | |
'<div class="input-group">' + | |
'<input type="text" class="form-control" ngModel required>' + | |
'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>' + | |
'</div>', | |
link: function(scope, element, attrs) { | |
console.log('link') | |
var input = element.find('input'); | |
var nowTemp = new Date(); | |
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(),0,0,0,0); | |
input.datepicker({ | |
format: "yyyy-mm-dd", | |
onRender: function(date) { | |
return date.valueOf() < now.valueOf() ? 'disabled' : ''; | |
} | |
}).on('changeDate', function(ev) { | |
scope.ngModel = input.val(); | |
console.info('date-picker event', input.val(), scope.ngModel); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<date-picker ng-model="date-a" id="date-a"></date-picker>