jquery - Bootstrap datepicker doesn't fire on first click -
i'm using following code displaying inline datepicker;
$('.show_datepicker').datepicker({ weekstart: 1, startdate : '2013-07-31', enddate : '2013-09-30', format : 'yyyy-mm-dd', }).on('changedate', function(e){ $('.datepicker-inline').on('click', '.datepicker_days:not(.disabled)', function() { $('.loading').show(); // show loading icon $("#loading_div").load("loading_url.php",function(){ $('.loading').hide(); // hide loading icon when finished }); }); });
problem 1
it works well, beside fact doesn't fire when click day first time. after initial click it's ok long i'm on page. everytime refresh page, have click date first time work afterwards.
i suppose it's because of seperate onclick event inside function, need exclude .disabled days call , can't work.
problem 2
console.log() tells me it's firing multiple times - when click second time it's firing 4 times, when click again it's firing 6 times, , on.
any ideas appreciated!
update:
this html-code rendered datepicker:
<div id="datepicker" class="show_datepicker table table-hover table-striped" data-date="2013-08-01"> <div class="datepicker datepicker-inline"> <div class="datepicker-days" style="display: block;"> <table class=" table-condensed"> [...] <tbody> <tr> [...] <td class="datepicker_days day alternative" id="2013-08-12">12</td> <td class="datepicker_days day alternative" id="2013-08-13">13</td> <td class="datepicker_days day" id="2013-08-14">14</td> <td class="datepicker_days day inaktiv btn-link disabled" id="2013-08-15">15</td> <td class="datepicker_days day" id="2013-08-16">16</td> <td class="datepicker_days day" id="2013-08-17">17</td> <td class="datepicker_days day disabled inaktiv btn-link" id="2013-08-18">18</td> [...] </tr> </tbody> [...] </table> </div> </div>
if changedate
not fire when clicking on .disabled
dates not need worry filtering invalid dates. can remove click handler correctly suspect causing multiple firings , not responding first click -- didn't change date yet click handler wasn't registered.
.on('changedate', function(e){ // won't fire on .disabled date anyway $('.loading').show(); // show loading icon $("#loading_div").load("loading_url.php",function(){ $('.loading').hide(); // hide loading icon when finished }); });
Comments
Post a Comment