Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine jQuery-ui datepicker's localization and initialization parameters

I want to have my localized datepicker not allow certain dates picking.

Localization:

$("#datepicker").datepicker($.datepicker.regional["fr"]);

No weekends :

$("#datepicker").datepicker({ beforeShowDay: $.datepicker.noWeekends })

I cannot figure out how to combine both?

like image 729
mishap Avatar asked Apr 21 '12 01:04

mishap


1 Answers

$.datepicker.regional attribute attribute holds an array of localizations; which themselves are "presets" of the datepicker options. To append your options (overwriting if necessary):

// use $.extend to merge preset options plus your options
$("#datepicker1")
    .datepicker($.extend({}, $.datepicker.regional.fr, {
        beforeShowDay: $.datepicker.noWeekends
    }));

// initialize the datepicker, then use .datepicker("option", options) method twice
$("#datepicker2")
    .datepicker()
    .datepicker("option", $.datepicker.regional.fr)
    .datepicker("option", "beforeShowDay", $.datepicker.noWeekends);

Demo (see example 5)

like image 120
Salman A Avatar answered Nov 08 '22 21:11

Salman A