From 3acb6807ab24a0026701da1cd368323c66a198bd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 12 Aug 2016 17:16:03 +0200 Subject: [PATCH] Added option to disable datepicker clear button --- .../files/js/WoltLabSuite/Core/Date/Picker.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js index 1bb2f71481..028ea7f590 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js @@ -49,6 +49,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment var isDateTime = (elAttr(element, 'type') === 'datetime'); var isTimeOnly = (isDateTime && elDataBool(element, 'time-only')); + var disableClear = elDataBool(element, 'disable-clear'); elData(element, 'is-date-time', isDateTime); elData(element, 'is-time-only', isTimeOnly); @@ -134,16 +135,18 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment element.parentNode.insertBefore(container, element); container.insertBefore(element, button); - button = elCreate('a'); - button.className = 'inputSuffix button'; - button.addEventListener(WCF_CLICK_EVENT, this.clear.bind(this, element)); - if (isEmpty) button.style.setProperty('visibility', 'hidden', ''); - - container.appendChild(button); - - icon = elCreate('span'); - icon.className = 'icon icon16 fa-times'; - button.appendChild(icon); + if (!disableClear) { + button = elCreate('a'); + button.className = 'inputSuffix button'; + button.addEventListener(WCF_CLICK_EVENT, this.clear.bind(this, element)); + if (isEmpty) button.style.setProperty('visibility', 'hidden', ''); + + container.appendChild(button); + + icon = elCreate('span'); + icon.className = 'icon icon16 fa-times'; + button.appendChild(icon); + } // check if the date input has one of the following classes set otherwise default to 'short' var hasClass = false, knownClasses = ['tiny', 'short', 'medium', 'long']; @@ -161,6 +164,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment clearButton: button, shadow: shadowElement, + disableClear: disableClear, isDateTime: isDateTime, isEmpty: isEmpty, isTimeOnly: isTimeOnly, @@ -484,7 +488,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment _input.value = value; elData(_input, 'value', date.getTime()); - data.clearButton.style.removeProperty('visibility'); + if (!data.disableClear) data.clearButton.style.removeProperty('visibility'); data.shadow.value = shadowValue; }, @@ -718,7 +722,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment element.removeAttribute('data-value'); element.value = ''; - data.clearButton.style.setProperty('visibility', 'hidden', ''); + if (!data.disableClear) data.clearButton.style.setProperty('visibility', 'hidden', ''); data.isEmpty = true; data.shadow.value = ''; }, -- 2.20.1