Introduction
I'm using the jQuery datepicker plugin in one of my applications. On one page their are multiple input elements which contains an instance of the datepicker plugin.
But each element has some differences set on the datepicker properties.
Also the onSelect event has a function that is different from each other instance.
Example
First element:
$("input[id*=txtEmployeeBirthDate]").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
showAnim: "slideDown",
dayNamesMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"],
monthNamesShort: ["jan", "feb", "mar", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec"],
yearRange: "1900:2050",
onSelect: function (dateText, inst) {
$("input[id$=hdnBirthDate]").val(dateText);
}
});
Second element:
$("input[id*=txtHolidayDate]").datepicker({
changeMonth: false,
changeYear: false,
dateFormat: "dd-mm-yy",
showAnim: "slideDown",
dayNamesMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"],
monthNamesShort: ["jan", "feb", "mar", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec"],
monthNames: ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"],
yearRange: _y + ":" + _y, // _y is a private variable which contains the current year
onSelect: function (dateText, inst) {
$("input[id$=hdnHolidayDate]").val(dateText);
}
});
Problem
The problem is that I have more then 5 different instances of the datepicker plugin.
And I would like to format or compact the code, because some properties like dateFormat and monthNamesShort are always the same.
Question
Is their a way to do this? Override the datepicker? Or what solution would be the best?