Skip to content

Instantly share code, notes, and snippets.

@dbajpeyi
Last active December 26, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbajpeyi/7134637 to your computer and use it in GitHub Desktop.
Save dbajpeyi/7134637 to your computer and use it in GitHub Desktop.
A simple angularjs directive for bootstrap datepicker
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);
});
}
}
});
@dbajpeyi
Copy link
Author

<date-picker ng-model="date-a" id="date-a"></date-picker>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment