Last active
August 29, 2015 14:02
-
-
Save stormsson/5a50c4e5e65f3eb36157 to your computer and use it in GitHub Desktop.
JS - Angular jQueryui datepicker directive
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
//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