Skip to content

Commit 25e55ff

Browse files
committed
Add support for an optional clear button on the date picker, that defaults to off. Fixes bug #4162.
1 parent 90caa93 commit 25e55ff

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ui/jquery.ui.datepicker.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Datepicker() {
4141
this.regional = []; // Available regional settings, indexed by language code
4242
this.regional[''] = { // Default regional settings
4343
closeText: 'Done', // Display text for close link
44+
clearText: 'Clear', // Display text for clear link
4445
prevText: 'Prev', // Display text for previous month link
4546
nextText: 'Next', // Display text for next month link
4647
currentText: 'Today', // Display text for current month link
@@ -104,6 +105,8 @@ function Datepicker() {
104105
altFormat: '', // The date format to use for the alternate field
105106
constrainInput: true, // The input is constrained by the current date format
106107
showButtonPanel: false, // True to show button panel, false to not show it
108+
showCloseButton: true, // True to show the 'Done' button on the button panel, if the panel is visible.
109+
showClearButton: false, // True to show the 'Clear' button on the button panel, if the panel is visible.
107110
autoSize: false // True to size the input for the date format, false to leave as is
108111
};
109112
$.extend(this._defaults, this.regional['']);
@@ -1405,8 +1408,13 @@ $.extend(Datepicker.prototype, {
14051408
var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
14061409
currentText = (!navigationAsDateFormat ? currentText :
14071410
this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
1408-
var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1411+
var showCloseButton = this._get(inst, 'showCloseButton');
1412+
var showClearButton = this._get(inst, 'showClearButton');
1413+
var closeText = ((!inst.inline && showCloseButton) ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
14091414
'.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
1415+
var clearText = ((!inst.inline && showClearButton) ? '<button type="button" class="ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1416+
'.datepicker._clearDate(' + inst.id + ');">' + this._get(inst, 'clearText') + '</button>' : '');
1417+
var controls = (isRTL ? (clearText + closeText) : (closeText + clearText));
14101418
var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
14111419
(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
14121420
'.datepicker._gotoToday(\'#' + inst.id + '\');"' +

0 commit comments

Comments
 (0)