Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reinitialize a bootstrap datepicker?

A bootstrap datepicker is initialized on load. How can I change the options for that datepicker after the page is loaded and the datepicker has already been initialized?

See here for an example http://jsfiddle.net/Leoqs1xg/

The weekStart is set to 4 (Thursday) at first with

$('#mydate').datepicker({weekStart: 4});

but if I change it to something else with

$('#mydate').datepicker({weekStart: 1});

weekStart is still 4.

like image 224
RatTub Avatar asked Dec 02 '22 18:12

RatTub


1 Answers

There is now a method destroy available.

I would do it like this:

$('#sv_pickup_date').datepicker('destroy').datepicker({
    format: 'dd/mm/yyyy'
    , autoclose: true
    , startDate: '20/08/2018'
    , endDate: '24/08/2018'
});

Optionally you may want to also use clearDates method.

Like this you can define your own reinitialize method for bootstap datepicker.

like image 149
DonJoe Avatar answered Dec 11 '22 17:12

DonJoe