Last active
December 21, 2015 08:28
-
-
Save lemming/6278002 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
angular.module('saSchedulerApp.directives') | |
.directive('pickadate', [function () { | |
return { | |
require: '?ngModel', | |
link: function (scope, elm, attrs, ngModel) { | |
var pickadateOptions = { format: 'dd.mm.yyyy' }; | |
if (!ngModel) { | |
$(elm).pickadate(pickadateOptions); | |
return; | |
} | |
pickadateOptions.onSet = function(event) { | |
var date = null; | |
if (event.select) { | |
date = new Date(event.select).toISOString(); | |
} | |
var phase = scope.$root.$$phase; | |
if (!~['$apply', '$digest'].indexOf(phase)) { | |
scope.$apply(function() { | |
ngModel.$setViewValue(date); | |
}); | |
} | |
}; | |
var $input = $(elm).pickadate(pickadateOptions), | |
picker = $input.pickadate('picker'); | |
ngModel.$render = function() { | |
picker.set('select', new Date(ngModel.$viewValue)); | |
} | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment