Skip to content

Instantly share code, notes, and snippets.

@Tjorriemorrie
Last active December 21, 2015 10:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tjorriemorrie/6293756 to your computer and use it in GitHub Desktop.
Save Tjorriemorrie/6293756 to your computer and use it in GitHub Desktop.
bootstrap 3 datetimepicker directive
'use strict'
angular.module('directives', [])
.directive('dateTimePicker', function() {
return {
restrict: 'E',
require: ['ngModel'],
scope: {
ngModel: '='
},
replace: true,
template:
'<div class="form-group">' +
'<label for="formLeadDate" class="control-label">Date</label>' +
'<div class="input-group">' +
'<input type="text" id="formLeadDate" class="form-control" ngModel>' +
'<span class="input-group-addon"><i class="icon-calendar"></i></span>' +
'</div>' +
'</div>',
link: function(scope, element, attrs) {
var input = element.find('input');
input.datetimepicker({
format: "yyyy/mm/dd hh:ii",
showMeridian: false,
autoclose: true,
todayBtn: true,
todayHighlight: true,
endDate: new Date()
});
element.bind('blur keyup change', function() {
scope.ngModel = input.val();
console.info('date-time-picker event', input.val(), scope.ngModel);
});
}
}
});
@Tjorriemorrie
Copy link
Author

<date-time-picker ng-model="leadNew.date"></date-time-picker>

@markovic131
Copy link

Should be:

input.bind('blur keyup change click', function() {

insted of

element.bind

@eremeevdev
Copy link

Also i think that after scope.ngModel = input.val(); must be scope.$apply();

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