]
},
+ {
+ title: 'Alternate Field and Format',
+ desc: 'Simultaneously update an alternate field using an alternate date format. ' +
+ 'This could be used to display selected dates in one format, while submitting ' +
+ 'the dates in another format from a hidden field. The alternate field is ' +
+ 'displayed here to demonstrate the functionality.',
+ html: '<input type="text" size="24" value="" id="alt1" readonly="readonly"/>\n' +
+ '<input type="text" size="24" value="" id="alt2" readonly="readonly"/>',
+ destroy: '$("#alt1").datepicker("destroy"); $("#alt2").val("");',
+
+ options: [
+ { desc: 'Single date selection', source: '$("#alt1").datepicker({altField: "#alt2", altFormat: "yy-mm-dd", showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' },
+ { desc: 'Range date selection', source: '$("#alt1").datepicker({altField: "#alt2", altFormat: "yy-mm-dd", rangeSelect: true, numberOfMonths: 2, showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' }
+ ]
+ },
+
{
title: 'Default Date',
desc: 'Control which date is shown if the datepicker is opened with no value. The default is today.',
numberOfMonths: 1, // Number of months to show at a time
stepMonths: 1, // Number of months to step back/forward
rangeSelect: false, // Allows for selecting a date range on one date picker
- rangeSeparator: ' - ' // Text between two dates in a range
+ rangeSeparator: ' - ', // Text between two dates in a range
+ altField: '', // Selector for an alternate field to store selected dates into
+ altFormat: '' // The date format to use for the alternate field
};
$.extend(this._defaults, this.regional['']);
this._datepickerDiv = $('<div id="' + this._mainDivId + '"></div>');
_selectDate: function(id, dateStr) {
var inst = this._getInst(id);
dateStr = (dateStr != null ? dateStr : inst._formatDate());
- if (inst._rangeStart)
- dateStr = inst._formatDate(inst._rangeStart) + inst._get('rangeSeparator') + dateStr;
+ if (inst._get('rangeSelect') && dateStr)
+ dateStr = (inst._rangeStart ? inst._formatDate(inst._rangeStart) :
+ dateStr) + inst._get('rangeSeparator') + dateStr;
if (inst._input)
inst._input.val(dateStr);
+ this._updateAlternate(inst);
var onSelect = inst._get('onSelect');
if (onSelect)
onSelect.apply((inst._input ? inst._input[0] : null), [dateStr, inst]); // trigger custom callback
this._lastInput = null;
}
},
+
+ /* Update any alternate field to synchronise with the main field. */
+ _updateAlternate: function(inst) {
+ var altField = inst._get('altField');
+ if (altField) { // update alternate field too
+ var altFormat = inst._get('altFormat');
+ var date = inst._getDate();
+ dateStr = (isArray(date) ? (!date[0] && !date[1] ? '' :
+ $.datepicker.formatDate(altFormat, date[0], inst._getFormatConfig()) +
+ inst._get('rangeSeparator') + $.datepicker.formatDate(
+ altFormat, date[1] || date[0], inst._getFormatConfig())) :
+ $.datepicker.formatDate(altFormat, date, inst._getFormatConfig()));
+ $(altField).each(function() { $(this).val(dateStr); });
+ }
+ },
/* Set as beforeShowDay function to prevent selection of weekends.
@param date Date - the date to customise
return target;
};
+/* Determine whether an object is an array. */
+function isArray(a) {
+ return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
+ (a.constructor && a.constructor.toString().match(/\Array\(\)/))));
+};
+
/* Invoke the datepicker functionality.
@param options String - a command, optionally followed by additional parameters or
Object - settings for attaching new datepicker functionality