summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VTextField.java2
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPosition.java42
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java30
3 files changed, 73 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTextField.java b/client/src/main/java/com/vaadin/client/ui/VTextField.java
index 1554bd1a22..1268b8a078 100644
--- a/client/src/main/java/com/vaadin/client/ui/VTextField.java
+++ b/client/src/main/java/com/vaadin/client/ui/VTextField.java
@@ -423,7 +423,7 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler,
*/
protected boolean updateCursorPosition() {
if (WidgetUtil.isAttachedAndDisplayed(this)) {
- int cursorPos = getCursorPos();
+ int cursorPos = prompting ? 0 : getCursorPos();
if (lastCursorPos != cursorPos) {
client.updateVariable(paintableId,
TextFieldConstants.VAR_CURSOR, cursorPos, false);
diff --git a/uitest/src/main/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPosition.java b/uitest/src/main/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPosition.java
new file mode 100644
index 0000000000..b8f9c9aa3f
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPosition.java
@@ -0,0 +1,42 @@
+package com.vaadin.tests.components.textfield;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TextField;
+
+public class InputPromptAndCursorPosition extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final TextField tf = new TextField();
+ tf.setColumns(40);
+ tf.setValue("Delete this text to reveal input prompt and update cursor position.");
+ tf.setInputPrompt("This is an input prompt");
+
+ final Label l = new Label("Cursor position: ?");
+ Button button = new Button("Update cursor position", new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ l.setValue("Cursor position: " + tf.getCursorPosition());
+ }
+ });
+
+ addComponent(tf);
+ addComponent(l);
+ addComponent(button);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Cursor position should always be zero when input prompt is displayed.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 19766;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java b/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java
new file mode 100644
index 0000000000..e688a313d3
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java
@@ -0,0 +1,30 @@
+package com.vaadin.tests.components.textfield;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class InputPromptAndCursorPositionTest extends MultiBrowserTest {
+
+ @Test
+ public void verifyDatePattern() {
+ openTestURL();
+
+ // Clear the current value and reveal the input prompt.
+ TextFieldElement textFieldElement = $(TextFieldElement.class).get(0);
+ textFieldElement.setValue("");
+
+ // Update cursor position.
+ $(ButtonElement.class).get(0).click();
+
+ // The cursor position should now be zero (not the input prompt length).
+ LabelElement cursorPosLabel = $(LabelElement.class).get(1);
+ assertEquals(cursorPosLabel.getText(), "Cursor position: 0");
+ }
+
+}