Skip to content

Instantly share code, notes, and snippets.

@stormsson
Last active August 29, 2015 14:02
Show Gist options
  • Save stormsson/5a50c4e5e65f3eb36157 to your computer and use it in GitHub Desktop.
Save stormsson/5a50c4e5e65f3eb36157 to your computer and use it in GitHub Desktop.
JS - Angular jQueryui datepicker directive
//Template:
//<input type="text" id="from" ng-model="filter.from" ng-change="getPage(1)" limitMinTo="to" jqdatepicker />
//<input type="text" id="to" ng-model="filter.to" ng-change="getPage(1)" limitMaxTo="from" jqdatepicker />
.directive('jqdatepicker', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
$(element).datepicker({
dateFormat: 'yy-mm-dd',
onClose: function(date)
{
if(attrs['limitminto'])
{
if(date)
{
$('#'+attrs['limitminto']).datepicker('option', 'minDate', date);
}
else
{
$('#'+attrs['limitminto']).datepicker('option', 'minDate', null);
}
}
if(attrs['limitmaxto'])
{
if(date)
{
$('#'+attrs['limitmaxto']).datepicker('option', 'maxDate', date);
}
else
{
$('#'+attrs['limitmaxto']).datepicker('option', 'maxDate', null);
}
}
},
onSelect: function (date) {
ngModelCtrl.$setViewValue(date);
ngModelCtrl.$render();
scope.$apply();
}
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment