GWT 日期框水印/占位符

发布于 2024-11-16 22:00:38 字数 242 浏览 12 评论 0原文

我想在 GWT DateBox 内设置水印/占位符。我知道如何使用 onFocus 和 onBlur 在普通文本框中设置水印/占位符。我认为在 DateBox 中这样做会相对相似。目前设置文本看起来像这样,但什么也不做。

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

有什么原因导致这行不通吗?

I want to set a watermark/placeholder inside of a 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你只要分分秒秒 2024-11-23 22:00:38
box.getTextBox().setValue("mm/dd/yyyy");
box.getTextBox().setValue("mm/dd/yyyy");
岁月染过的梦 2024-11-23 22:00:38

我想您实际上在这里谈论的是能够设置占位符文本。我之前在此处发布了 TextBox 元素的解决方案。该过程非常相似:

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);
  }
}

然后将 DateBox 对象替换为 DateField 对象,然后只需调用 someDateField.setPlaceholder("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");.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文