Load the wodp plugin:
<link rel="stylesheet" href="wodp.css"/> <script src="jquery.js" type="text/javascript"></script> <script src="wodp.js" type="text/javascript"></script>
A DatePicker is always attached to an <input> DOM element that will contain the selected date (YYYY-MM-DD) or the selected range (YYYY-MM-DD,YYYY-MM-DD). It will display a month calendar for the user to select the date. This calendar can be made 'permanent' (ie. always displayed) or can be shown only when user clicks on the <input> element itself or its optionally associated calendar icon.
Selecting dates:
Accepting user's typed-in date into the attached <input> DOM element is left to the developper: eg. 1) by using change event on the attached <input> DOM element and 2) optionaly checking that the typed-in date (or range) is within wodp defined range by using the public wodp method 'inrange()'
Wodp attaches two elements to the <input> DOM element (using element's .data): 1) a wodp object self-pointer to access wodp settings (to, from,...) or public methods (inrange,...) : inputel.data('wodp'); 2) a description of the value selected by the user, inputel.data('wodpdesc') = 'range', 'ranging', 'day', 'week', 'month' or 'year'.
Example: a calendar, with its non-visible <input> element, a limited range of selectable dates, using the default days/months names and no holidays and triggering your own javascript code (ie. the 'onpicked' callback) that shows the selected date (and its description) here: ()
<input id="d0" class="wodp" type="text"/>
$('input#d0').css('display','none').wodp({
popup: false,
holidays: [],
range: {from: "2014-11-05", to:"2016-04-30"},
onpicked: function() {
$("#d0view").text($("#d0").val());
$("#d0viewdesc").text($("#d0").data('wodpdesc'));
},
});
Example: a popup calendar when user clicks on the <input> element
<input id="d1" class="wodp" type="text" width="50"/>
$('input#d1').wodp();
date1:
Example: a popup calendar with hidden input and associated calendar icon
<input id="d2" class="wodp" type="text" width="50"/>
$('input#d2').wodp({"icon": true, offX:10, offY:10 });
date2
Example: a popup calendar when user clicks on associated calendar icon, and alert on invalid date entered
<input id="d22" class="wodp" type="text" size="22"/>
$('input#d22').wodp({
icon: true ,
oninvalid: function() { alert('invalid date entered '+$('input#d22').val()) }
});
Example: a calendar, localized
<input id="d3" class="wodp" type="text"/>
months = ["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"];
days = ["Lu","Ma","Me","Je","Ve","Sa","Di"];
h = [
{d: "$Y-01-01" , t: "Jour de l'An"},
{d: "$PQ 1", t: "Lundi de Pâques"},
{d: "$Y-05-01", t: "Fête du Travail"},
{d: "$PQ 39", t: "Ascension"},
{d: "$PQ 50", t: "Lundi de Pentecôte"},
{d: "$Y-05-08", t: "Armistice 1945"},
{d: "$Y-07-14", t: "Fête Nationale"},
{d: "$Y-08-15", t: "Assomption"},
{d: "$Y-11-01", t: "Toussaint"},
{d: "$Y-11-11", t: "Armistice 1918"},
{d: "$Y-12-25", t: "Noël"}
];
$('input#d3').css('display','none').wodp({
popup: false,
holidays: h,
months: months,
days: days
});
wodp default options: