Skip to content

Commit 06947c6

Browse files
authored
Moving disableBrowserAutocomplete to WidgetUtil and change widgets to use it (vaadin#12020)
* 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
1 parent 4014f80 commit 06947c6

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

client/src/main/java/com/vaadin/client/WidgetUtil.java

+22
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.google.gwt.user.client.EventListener;
4343
import com.google.gwt.user.client.Window;
4444
import com.google.gwt.user.client.ui.RootPanel;
45+
import com.google.gwt.user.client.ui.TextBox;
4546
import com.google.gwt.user.client.ui.Widget;
4647
import com.vaadin.shared.ui.ErrorLevel;
4748
import com.vaadin.shared.util.SharedUtil;
@@ -1962,4 +1963,25 @@ public static Element createErrorIndicatorElement() {
19621963
return indicator;
19631964
}
19641965
}
1966+
1967+
public static void disableBrowserAutocomplete(TextBox textBox) {
1968+
/*-
1969+
* Stop the browser from showing its own suggestion popup.
1970+
*
1971+
* Using an invalid value instead of "off" as suggested by
1972+
* https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
1973+
*
1974+
* Leaving the non-standard Safari options autocapitalize and
1975+
* autocorrect untouched since those do not interfere in the same
1976+
* way, and they might be useful in a combo box where new items are
1977+
* allowed.
1978+
*/
1979+
if (BrowserInfo.get().isChrome()) {
1980+
// Chrome supports "off" and random number does not work with
1981+
// Chrome
1982+
textBox.getElement().setAttribute("autocomplete", "off");
1983+
} else {
1984+
textBox.getElement().setAttribute("autocomplete", Math.random() + "");
1985+
}
1986+
}
19651987
}

client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.vaadin.client.Focusable;
3737
import com.vaadin.client.LocaleNotLoadedException;
3838
import com.vaadin.client.LocaleService;
39+
import com.vaadin.client.WidgetUtil;
3940
import com.vaadin.client.ui.aria.AriaHelper;
4041
import com.vaadin.client.ui.aria.HandlesAriaCaption;
4142
import com.vaadin.client.ui.aria.HandlesAriaInvalid;
@@ -90,6 +91,8 @@ public VAbstractTextualDate(R resoluton) {
9091
if (BrowserInfo.get().isIE()) {
9192
addDomHandler(this, KeyDownEvent.getType());
9293
}
94+
// Stop the browser from showing its own suggestion popup.
95+
WidgetUtil.disableBrowserAutocomplete(text);
9396
add(text);
9497
publishJSHelpers(getElement());
9598
}

client/src/main/java/com/vaadin/client/ui/VComboBox.java

+1-18
Original file line numberDiff line numberDiff line change
@@ -1438,24 +1438,7 @@ public class FilterSelectTextBox extends TextBox {
14381438
* @since 7.6.4
14391439
*/
14401440
public FilterSelectTextBox() {
1441-
/*-
1442-
* Stop the browser from showing its own suggestion popup.
1443-
*
1444-
* Using an invalid value instead of "off" as suggested by
1445-
* https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
1446-
*
1447-
* Leaving the non-standard Safari options autocapitalize and
1448-
* autocorrect untouched since those do not interfere in the same
1449-
* way, and they might be useful in a combo box where new items are
1450-
* allowed.
1451-
*/
1452-
if (BrowserInfo.get().isChrome()) {
1453-
// Chrome supports "off" and random number does not work with
1454-
// Chrome
1455-
getElement().setAttribute("autocomplete", "off");
1456-
} else {
1457-
getElement().setAttribute("autocomplete", Math.random() + "");
1458-
}
1441+
WidgetUtil.disableBrowserAutocomplete(this);
14591442
}
14601443

14611444
/**

compatibility-client/src/main/java/com/vaadin/v7/client/ui/VFilterSelect.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -1409,23 +1409,8 @@ public class FilterSelectTextBox extends TextBox {
14091409
* @since 7.6.4
14101410
*/
14111411
public FilterSelectTextBox() {
1412-
/*-
1413-
* Stop the browser from showing its own suggestion popup.
1414-
*
1415-
* Using an invalid value instead of "off" as suggested by
1416-
* https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
1417-
*
1418-
* Leaving the non-standard Safari options autocapitalize and
1419-
* autocorrect untouched since those do not interfere in the same
1420-
* way, and they might be useful in a combo box where new items are
1421-
* allowed.
1422-
*/
1423-
if (BrowserInfo.get().isChrome()) {
1424-
// Chrome supports "off" and random number does not work with Chrome
1425-
getElement().setAttribute("autocomplete", "off");
1426-
} else {
1427-
getElement().setAttribute("autocomplete", Math.random() + "");
1428-
}
1412+
// Stop the browser from showing its own suggestion popup.
1413+
WidgetUtil.disableBrowserAutocomplete(this);
14291414
}
14301415

14311416
/**

compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.vaadin.client.Focusable;
3636
import com.vaadin.client.LocaleNotLoadedException;
3737
import com.vaadin.client.LocaleService;
38+
import com.vaadin.client.WidgetUtil;
3839
import com.vaadin.client.ui.SubPartAware;
3940
import com.vaadin.client.ui.aria.AriaHelper;
4041
import com.vaadin.client.ui.aria.HandlesAriaCaption;
@@ -115,6 +116,8 @@ public void onBlur(BlurEvent event) {
115116
if (BrowserInfo.get().isIE()) {
116117
addDomHandler(this, KeyDownEvent.getType());
117118
}
119+
// Stop the browser from showing its own suggestion popup.
120+
WidgetUtil.disableBrowserAutocomplete(text);
118121
add(text);
119122
}
120123

0 commit comments

Comments
 (0)