]> source.dussan.org Git - vaadin-framework.git/commitdiff
Moving disableBrowserAutocomplete to WidgetUtil and change widgets to use it (#12020) pr12027/r14
authorTatu Lund <tatu@vaadin.com>
Mon, 25 May 2020 07:52:56 +0000 (10:52 +0300)
committerGitHub <noreply@github.com>
Mon, 25 May 2020 07:52:56 +0000 (10:52 +0300)
* Add autocomplete prevention to DateField

Autocomplete popup will interfere DateField's own popup

* Adding disableBrowserAutocomplete(..) in WidgetUtil

* Change VComboBox to use WidgetUtil.disableBrowserAutocomplete(..)

* Change to use WidgetUtil.disableBrowserAutocomplete(..)

* Change VFilterSelect to use WidgetUtil.disableBrowserAutocomplete(..)

* Adding WidgetUtil.disableBrowserAutocomplete to VTextualDate

* Adding missing import

* Adding missing import

client/src/main/java/com/vaadin/client/WidgetUtil.java
client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
client/src/main/java/com/vaadin/client/ui/VComboBox.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VFilterSelect.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java

index 6906f5fa5ee9d5b6c95503a0228db99c1e2cad2f..7a268a0a8aeb8fb5916c6bb1138b29e3d074b499 100644 (file)
@@ -42,6 +42,7 @@ import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.EventListener;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.shared.ui.ErrorLevel;
 import com.vaadin.shared.util.SharedUtil;
@@ -1962,4 +1963,25 @@ public class WidgetUtil {
             return indicator;
         }
     }
+
+    public static void disableBrowserAutocomplete(TextBox textBox) {
+        /*-
+         * Stop the browser from showing its own suggestion popup.
+         *
+         * Using an invalid value instead of "off" as suggested by
+         * https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
+         *
+         * Leaving the non-standard Safari options autocapitalize and
+         * autocorrect untouched since those do not interfere in the same
+         * way, and they might be useful in a combo box where new items are
+         * allowed.
+         */
+        if (BrowserInfo.get().isChrome()) {
+            // Chrome supports "off" and random number does not work with
+            // Chrome
+            textBox.getElement().setAttribute("autocomplete", "off");
+        } else {
+               textBox.getElement().setAttribute("autocomplete", Math.random() + "");
+        }      
+    }
 }
index bf79fec5454a496df986d9415329b7739c6c07e4..5fd4fe6c552ab2ba865beec2d11062c63bc0934d 100644 (file)
@@ -36,6 +36,7 @@ import com.vaadin.client.BrowserInfo;
 import com.vaadin.client.Focusable;
 import com.vaadin.client.LocaleNotLoadedException;
 import com.vaadin.client.LocaleService;
+import com.vaadin.client.WidgetUtil;
 import com.vaadin.client.ui.aria.AriaHelper;
 import com.vaadin.client.ui.aria.HandlesAriaCaption;
 import com.vaadin.client.ui.aria.HandlesAriaInvalid;
@@ -90,6 +91,8 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
         if (BrowserInfo.get().isIE()) {
             addDomHandler(this, KeyDownEvent.getType());
         }
+        // Stop the browser from showing its own suggestion popup.
+        WidgetUtil.disableBrowserAutocomplete(text);
         add(text);
         publishJSHelpers(getElement());
     }
index cf06e06b2debc7866fabe919d5d953ea7aa73d5b..08c57f888aecef1f72b4a30de0e6a70d7a7395cf 100644 (file)
@@ -1438,24 +1438,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
          * @since 7.6.4
          */
         public FilterSelectTextBox() {
-            /*-
-             * Stop the browser from showing its own suggestion popup.
-             *
-             * Using an invalid value instead of "off" as suggested by
-             * https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
-             *
-             * Leaving the non-standard Safari options autocapitalize and
-             * autocorrect untouched since those do not interfere in the same
-             * way, and they might be useful in a combo box where new items are
-             * allowed.
-             */
-            if (BrowserInfo.get().isChrome()) {
-                // Chrome supports "off" and random number does not work with
-                // Chrome
-                getElement().setAttribute("autocomplete", "off");
-            } else {
-                getElement().setAttribute("autocomplete", Math.random() + "");
-            }
+            WidgetUtil.disableBrowserAutocomplete(this);
         }
 
         /**
index 86fa8ed50040d91d43f1b33aab1a5562648dccf9..d7ae6f3c0703a713acd0a85503b8d19f001d4f01 100644 (file)
@@ -1409,23 +1409,8 @@ public class VFilterSelect extends Composite
          * @since 7.6.4
          */
         public FilterSelectTextBox() {
-            /*-
-             * Stop the browser from showing its own suggestion popup.
-             *
-             * Using an invalid value instead of "off" as suggested by
-             * https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
-             *
-             * Leaving the non-standard Safari options autocapitalize and
-             * autocorrect untouched since those do not interfere in the same
-             * way, and they might be useful in a combo box where new items are
-             * allowed.
-             */
-            if (BrowserInfo.get().isChrome()) {
-                // Chrome supports "off" and random number does not work with Chrome
-                getElement().setAttribute("autocomplete", "off");                      
-            } else {
-                getElement().setAttribute("autocomplete", Math.random() + "");
-            }
+            // Stop the browser from showing its own suggestion popup.
+            WidgetUtil.disableBrowserAutocomplete(this);
         }
 
         /**
index 4d52e3e4f83281f691c30f423104ec3a0610fad2..e332e628fd9abb8e55674350cb4688c462feeb5b 100644 (file)
@@ -35,6 +35,7 @@ import com.vaadin.client.BrowserInfo;
 import com.vaadin.client.Focusable;
 import com.vaadin.client.LocaleNotLoadedException;
 import com.vaadin.client.LocaleService;
+import com.vaadin.client.WidgetUtil;
 import com.vaadin.client.ui.SubPartAware;
 import com.vaadin.client.ui.aria.AriaHelper;
 import com.vaadin.client.ui.aria.HandlesAriaCaption;
@@ -115,6 +116,8 @@ public class VTextualDate extends VDateField
         if (BrowserInfo.get().isIE()) {
             addDomHandler(this, KeyDownEvent.getType());
         }
+        // Stop the browser from showing its own suggestion popup.
+        WidgetUtil.disableBrowserAutocomplete(text);
         add(text);
     }