Added option to disable datepicker clear button
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Aug 2016 15:16:03 +0000 (17:16 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Aug 2016 15:16:08 +0000 (17:16 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js

index 1bb2f71481f18155fb4ab0628ab9d84f42c77a90..028ea7f5909b52c8051279c52f862612a52b8f3d 100644 (file)
@@ -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 = '';
                },