i'm trying use bootstrap datepicker eternicode in combination angularjs.
var app=angular.module('myapp', []) .controller('datectrl', function($scope) { // case 1: $scope.datepick = ''; // case 2: //$scope.datepick = '25.04.1986'; $scope.setfirstdate = function() { $scope.datepick= '13.10.1960'; }; $scope.setanotherdate = function() { $scope.datepick = '20.02.1967'; }; }); $(document).ready(function(){ $('.datepicker').datepicker({ autoclose: true, format: 'dd.mm.yyyy', clearbtn: true, todaybtn: 'linked', todayhighlight: true, weekstart: '1', calendarweeks: true, keyboardnavigation: false }); });
essentially, works fine. when change date programmatically, bs datepicker ignores it. shows, when load fiddle , follow these steps:
1) click on 'first me!'
2) select input field, without touching datepicker
3) tab out, press esc, or click anywhere datepicker (close without selecting date)
you'll see, input field empty.
this not happen because of invalid date-format suggested in this question: uncomment line 6 in fiddle , test case 2. repeat above steps. datefield shows '25.04.1986'.
also, in both cases can test clicking datepicker , repeating steps 1-3. input field show last date selected bs datepicker.
{{datepick}}
shows, ng-model accurate, question not duplicate of this or this question. seeing angularjs aware of actual date, don't see how scope.apply solve problem.
this tells me: bs datepicker keeping track of own , remember initial date or dates selected datepicker itself. , when closing without picking new one, reset input field remembered value.
so how can prevent happening?
so, found workaround problem. keep datepicker resetting input value, add:
forceparse: false
to datepicker options. see updated jsfiddle.
even though solves problem @ hand, keep in mind, datepicker no longer parse/check/correct inputs.
i believe bug , create issue @ github.
Comments
Post a Comment