开发者

GWT DateBox Watermark/Placeholder

I want to set a watermark/placeholder inside of a开发者_Go百科 GWT DateBox. I know how to use onFocus and onBlur to set up a watermark/placeholder in a normal TextBox. I assumed that doing so in a DateBox would be relatively similar. Setting up the text currently looks like this, but does nothing at all.

    Datebox box = new DateBox();
    box.getTextBox().setText("mm/dd/yyyy");

Is there a reason that this would not be working?


box.getTextBox().setValue("mm/dd/yyyy");


I imagine what you were actually talking about here was being able to set placeholder text. I posted a solution for TextBox elements here before. The process would be quite similar:

public class DateField extends DateBox {

  String placeholder = "";

  /**
   * Creates an empty DateField.
   */
  public DateField() {}

  /**
   * Gets the current placeholder text for the date box.
   * 
   * @return the current placeholder text
   */
  public String getPlaceholder() {
      return placeholder;
  }

  /**
   * Sets the placeholder text displayed in the date box.
   * 
   * @param placeholder the placeholder text
   */
  public void setPlaceholder(String text) {
      placeholder = (text != null ? text : "");
      getElement().setPropertyString("placeholder", placeholder);
  }
}

Then replace your DateBox objects with DateField objects, and you'd just call someDateField.setPlaceholder("mm/dd/yyyy");.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜