diff options
author | Keith Wood <kbwood.au@gmail.com> | 2008-06-21 23:51:34 +0000 |
---|---|---|
committer | Keith Wood <kbwood.au@gmail.com> | 2008-06-21 23:51:34 +0000 |
commit | ca17b9953ecfdb2e3c86c74b2e7cfa2cc4373d56 (patch) | |
tree | 0dd443309f0c65efa062f2b41d45780aea324450 /ui/ui.datepicker.js | |
parent | 2e3b8eac77fe95b583a945a022bced62c478408f (diff) | |
download | jquery-ui-ca17b9953ecfdb2e3c86c74b2e7cfa2cc4373d56.tar.gz jquery-ui-ca17b9953ecfdb2e3c86c74b2e7cfa2cc4373d56.zip |
Fixed 2038 Split out display date and date value formats
Diffstat (limited to 'ui/ui.datepicker.js')
-rw-r--r-- | ui/ui.datepicker.js | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index c04252da8..ced98633b 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -111,7 +111,9 @@ function Datepicker() { 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>'); @@ -691,10 +693,12 @@ $.extend(Datepicker.prototype, { _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 @@ -710,6 +714,21 @@ $.extend(Datepicker.prototype, { 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 @@ -1457,6 +1476,12 @@ function extendRemove(target, props) { 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 |