Bootstrap-datepicker: $.datepicker.setDefaults() available?

Created on 18 Dec 2012  路  5Comments  路  Source: uxsolutions/bootstrap-datepicker

I looked all over for this but I don't see a way to set default options for all datepickers like I can with jQuery-UI. Is such an option available in the present version?

Thanks for this very helpful version of the datepicker!

Most helpful comment

As this was the top hit on Google for me when I searched, the latest version of the datepicker requires something like this:

$.extend($.fn.datepicker.defaults, {
    autoclose: true,
    format:'d M yyyy',
    orientation:'bottom left',
    todayHighlight: true,
    showOnFocus: false
});

All 5 comments

There's no method by that name, but there is $.datepicker.defaults. If you set options to this dict (which is actually empty in the current code...), they'll be used by any datepickers instantiated afterwards, unless overridden by normal options.

Thanks for the response. I must not have something right then, I'm trying the following:

    <script>
      $(document).ready(function(){
        $.datepicker.defaults({todayHighlight:true, autoclose:true});
      });
    </script>

:) It's not a function, it's just a raw hash/dictionary/object:

<script>
    $(document).ready(function(){
        $.datepicker.defaults = {todayHighlight:true, autoclose:true};
    });
</script>

That works, thank you

As this was the top hit on Google for me when I searched, the latest version of the datepicker requires something like this:

$.extend($.fn.datepicker.defaults, {
    autoclose: true,
    format:'d M yyyy',
    orientation:'bottom left',
    todayHighlight: true,
    showOnFocus: false
});
Was this page helpful?
0 / 5 - 0 ratings