diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2016-10-12 09:02:46 +0300 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2016-10-14 13:45:24 +0300 |
commit | ff4d7b1e9b7b4bf9a15bd199acc3d7a12c519cc2 (patch) | |
tree | 45dbbb15e1f3aa052c4ee619589d6d8b3731d52f /client | |
parent | 24e11dca6b074217d594e618727dfe7abf7c3a90 (diff) | |
download | vaadin-framework-ff4d7b1e9b7b4bf9a15bd199acc3d7a12c519cc2.tar.gz vaadin-framework-ff4d7b1e9b7b4bf9a15bd199acc3d7a12c519cc2.zip |
Use placeholder instead of inputPrompt for DateField
Renames the API server side and uses placeholder attribute for input.
Removed PopupDateFieldInputPrompt test since it tests input prompt logic,
that is no longer there after switching to native placeholder attribute
for input element.
Change-Id: I5c66456781f8703ba2e253134b88f8372825528f
Diffstat (limited to 'client')
3 files changed, 25 insertions, 43 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTextualDate.java b/client/src/main/java/com/vaadin/client/ui/VTextualDate.java index 7b83a5622d..b7c89c6397 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTextualDate.java +++ b/client/src/main/java/com/vaadin/client/ui/VTextualDate.java @@ -56,16 +56,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, /** For internal use only. May be removed or replaced in the future. */ public boolean lenient; - private static final String CLASSNAME_PROMPT = "prompt"; - - /** For internal use only. May be removed or replaced in the future. */ - public static final String ATTR_INPUTPROMPT = "prompt"; - - /** For internal use only. May be removed or replaced in the future. */ - public String inputPrompt = ""; - - private boolean prompting = false; - public VTextualDate() { super(); text = new TextBox(); @@ -75,10 +65,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, public void onFocus(FocusEvent event) { text.addStyleName(VTextField.CLASSNAME + "-" + VTextField.CLASSNAME_FOCUS); - if (prompting) { - text.setText(""); - setPrompting(false); - } if (getClient() != null && getClient() .hasEventListeners(VTextualDate.this, EventId.FOCUS)) { getClient().updateVariable(getId(), EventId.FOCUS, "", @@ -95,11 +81,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, text.removeStyleName(VTextField.CLASSNAME + "-" + VTextField.CLASSNAME_FOCUS); String value = getText(); - setPrompting(inputPrompt != null - && (value == null || "".equals(value))); - if (prompting) { - text.setText(readonly ? "" : inputPrompt); - } if (getClient() != null && getClient() .hasEventListeners(VTextualDate.this, EventId.BLUR)) { getClient().updateVariable(getId(), EventId.BLUR, "", true); @@ -204,15 +185,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, text.setEnabled(enabled); } - protected void setPrompting(boolean prompting) { - this.prompting = prompting; - if (prompting) { - addStyleDependentName(CLASSNAME_PROMPT); - } else { - removeStyleDependentName(CLASSNAME_PROMPT); - } - } - @Override @SuppressWarnings("deprecation") public void onChange(ChangeEvent event) { @@ -307,23 +279,35 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, text.setFocus(true); } - protected String getText() { - if (prompting) { - return ""; + /** + * Sets the placeholder for this textual date input. + * + * @param placeholder + * the placeholder to set, or {@code null} to clear + */ + public void setPlaceholder(String placeholder) { + if (placeholder != null) { + text.getElement().setAttribute("placeholder", placeholder); + } else { + text.getElement().removeAttribute("placeholder"); } + } + + /** + * Gets the set placeholder this textual date input, or an empty string if + * none is set. + * + * @return the placeholder or an empty string if none set + */ + public String getPlaceHolder() { + return text.getElement().getAttribute("placeholder"); + } + + protected String getText() { return text.getText(); } protected void setText(String text) { - if (inputPrompt != null && (text == null || "".equals(text)) - && !this.text.getStyleName().contains(VTextField.CLASSNAME + "-" - + VTextField.CLASSNAME_FOCUS)) { - text = readonly ? "" : inputPrompt; - setPrompting(true); - } else { - setPrompting(false); - } - this.text.setText(text); } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java index 7161283176..4a08399bdf 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java @@ -23,6 +23,7 @@ import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.user.client.ui.PopupPanel; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.UIDL; +import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.client.ui.VPopupCalendar; diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java index 45504cebd0..bf77d3b25f 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java @@ -38,9 +38,6 @@ public class TextualDateConnector extends AbstractDateFieldConnector { getWidget().formatStr = uidl.getStringAttribute("format"); } - getWidget().inputPrompt = uidl - .getStringAttribute(VTextualDate.ATTR_INPUTPROMPT); - getWidget().lenient = !uidl.getBooleanAttribute("strict"); getWidget().buildDate(); |