Closed sylouuu closed 7 years ago
With the original (jQuery) pickadate, you have to set data-value="2015-01-01"
to do the job. Obviously, it doesn't work with this Angular version.
Thanks for your example. So the variable for the binding should be set to ng-model and not to pick-a-date. pick-a-date seems to be not usefull in this angularjs version.
It works in case I write pick-a-date="myDate"
but pick-a-date-options="{ format: 'yyyy-mm-dd' }"
is not set, as the input result is: Thu Jan 01 2015 01:00:00 GMT+0100 (CET)
I was wondering about the date format as well
So we can't set an initial value? So that rules out bi-directional binding if the date is a result of an async request as well?
Is it something to be addressed? Would be good if we had some demos up front to know wether to pick this date selector. Shame, it looks promising for me but I need initial values as most forms usually have an edit screen (which needs to be pre-loaded). Awaiting eagerly for an update on this as I think it's the best date picker out so far.
Same as you @willks. Can't wait for the initial value support. I'm kind of stuck. ping @alongubkin
@willks, I believe the code is two way binding, but it wasn't monitoring the change of the value afterwards.
ok, i really hate the code is grunted, so i don't really know how to extend the code other than just add the following two lines
scope.$watch('pickADate', function() {
element.pickadate('picker').set('select', scope.pickADate);
});
after the setTimeout call,
setTimeout(function() {
if (scope.pickADate) {
element.pickadate('picker').set('select', scope.pickADate);
}
}, 1000);
Well for whatever reason, I couldn't get it working, so I just go back to the pickadate.js and then add the following directive (which is just the simplified version), and it worked. So there must be some bug in the current code.
app.directive('pickADate', function() {
return {
restrict: 'A',
scope: {
pickADate: '=',
pickADateOptions: '='
},
link: function(scope, elem, attrs) {
elem.pickadate();
setTimeout(function() {
if (scope.pickADate) {
elem.pickadate('picker').set('select', scope.pickADate);
}
}, 1000);
scope.$watch('pickADate', function() {
elem.pickadate('picker').set('select', scope.pickADate);
});
}
}
});
works for me if my initial date is (whyever) a javascript date object. anyway, code should be improved to get rid of the timeout and only use scope.$watch -> see here: https://github.com/jonathan-reisdorf/angular-datepicker/commit/f89b770cd45504294cfc9c7ac4ce4defd2b3139d
Works fine if we set default date as, pick-a-date="startDate" //startDate as $scope variable with whatever default date you want to and set date format as, $scope.options = { format: 'yyyy-mm-dd' }; at controller end.
Specify a default such as:
$scope.myDate = '2015-01-01';
The datepicker is still pointing on today.
Demo
Bests