As already pointed by @Boris Brudnoy there is no built-in way to do it with TextBox. Takin futher his suggestion it will be nice to extract this into new custom component (to simplify reuse and support):
- Add new package (for example
com.app.shared.customcontrol
) Add new CustomTextBox:
public class CustomTextBox extends TextBox { public void setAutocomplete(String value){ this.getElement().setAttribute("autocomplete", value); } public void setAutocapitalize(String value){ this.getElement().setAttribute("autocapitalize", value); } }
Declare new namespace using UI binder and use your component:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:c="urn:import:com.app.shared.customcontrol"> <g:HTMLPanel ...> <c:CustomTextBox ui:field="..." autocomplete="off" autocapitalize="off" /> </g:HTMLPanel> </ui:UiBinder>
As alternative way if you want apply these settings system wide you can do it via constructor:
public class CustomTextBox extends TextBox {
public CustomTextBox() {
this.getElement().setAttribute("autocomplete", "off");
this.getElement().setAttribute("autocapitalize", "off");
}
....
}