Djomla Djomla - 2 years ago 260
Javascript Question

Bootstrap Datepicker re-initialize date format

I have Bootstrap datepicker with default format mm/dd/yyyy, and I have select where I can change
format from mm/dd/yyyy to dd/mm/yyyy and reverse.

On select change I want to my datepicker change format.

I tried

find('#options-date_format').on('change', function(){
$("#picker").datepicker({format: formatDate})

but It's not working, and I can't find way of doing this.
Also tried to remove / destroy datepicker but I got javascript error.


Answer Source

Ok I resolve this extending bootstra-datepicker.js

setFormat: function(format) {
    this.format = DPGlobal.parseFormat(format);

And call that function

find('#options-date_format').on('change', function(){
    $("#picker").datepicker('setFormat', newFormat);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download