You must create your own SuggestBox widget, after which you can set the placeholder attribute for it. For instance:
public class CustomSuggestBox extends SuggestBox { private String placeHolderText = ""; public String getPlaceHolderText() { return placeHolderText; } public void setPlaceHolderText(String text) { placeHolderText = text; getTextBox().getElement().setAttribute("placeHolder", placeHolderText); } }
So, you can set this property in user interface binding.
<widgets:CustomSuggestBox ui:field="cSuggestBox" placeHolderText="someText" />
PS: It only works in a modern browser. For the correct implementation of old browsers, also check the third-party wogwt library, it has a TextBoxWithPlaceholder , which extends the TextBox:
/** * A text box that displays a placeholder string when empty * * <h3>CSS Style Rules</h3> * <ul class='css'> * <li>.wogwt-TextBoxWithPlaceholder { primary style }</li> * <li>.wogwt-TextBoxWithPlaceholder-placeholder { dependent style set when * the placeholder is displayed }</li> * </ul> */
In this case, you can send this TextBoxWithPlaceholder
instance to the TextBoxWithPlaceholder
constructor SuggestBox(SuggestOracle oracle, TextBoxBase box)
.
source share