Bootstrap datepicker toggle disable

邮差的信 提交于 2019-12-22 12:19:00

问题


I am using bootstrap-datepicker and getting an issue.

When I click a day, it works well,but when I click the same day again. The selection gets cancelled

The boostrap datepicker demo works well.

I had found the example for bootstrap date picker from the above link.


回答1:


It's a known issue. Here is a workaround for this issue.

https://github.com/eternicode/bootstrap-datepicker/issues/816

jsfiddle the issue: http://jsfiddle.net/antonkruger/fpgseobz/

Once I've tried it, I'll post an update.

Update: Yes it works.

In the defaults @ line 1394, add a new option, allowDeselection

var defaults = $.fn.datepicker.defaults = {
    allowDeselection: false,
    ...
};

In the _toggle_multidate function @ line 1015, modify the "else if (ix !== -1)" statement to:

else if (ix !== -1 && this.o.allowDeselection){
   this.dates.remove(ix);
}



回答2:


I came across this issue myself so if you still need this. trick is to store the current date in a variable each time a new date is created. If the new date is undefined (empty) update date with the temporary variable. I know its a dirty solution, but hey atleast its working.

I wrote a little fiddle enter code herehttp://jsfiddle.net/d86msex1/

Goodluck!




回答3:


There's now an official way to accomplish this:

$element.datepicker('remove');

source: http://bootstrap-datepicker.readthedocs.org/en/release/methods.html#remove



来源:https://stackoverflow.com/questions/24775260/bootstrap-datepicker-toggle-disable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!