]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ignore change btwn paints and force update unfocused TextField (#15144)
authorAMahdy AbdElAziz <amahdy7@gmail.com>
Wed, 7 Jan 2015 13:01:28 +0000 (15:01 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 20 Jan 2015 10:27:38 +0000 (10:27 +0000)
Change-Id: I0ddcea2a617fea00d707f7deaf155e98b9d6a832

client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java
uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPrompt.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPromptTest.java [new file with mode: 0644]

index 1a4b64b0a6262db7db4b3aa98740fdaee155f53c..0d85e98ee310d359a04bb77c52ab58667f33663c 100644 (file)
@@ -22,6 +22,7 @@ import com.google.gwt.user.client.Event;
 import com.vaadin.client.ApplicationConnection;
 import com.vaadin.client.Paintable;
 import com.vaadin.client.UIDL;
+import com.vaadin.client.Util;
 import com.vaadin.client.ui.AbstractFieldConnector;
 import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
 import com.vaadin.client.ui.VTextField;
@@ -83,14 +84,15 @@ public class TextFieldConnector extends AbstractFieldConnector implements
         }
         /*
          * We skip the text content update if field has been repainted, but text
-         * has not been changed. Additional sanity check verifies there is no
-         * change in the queue (in which case we count more on the server side
-         * value).
+         * has not been changed (#6588). Additional sanity check verifies there
+         * is no change in the queue (in which case we count more on the server
+         * side value). <input> is updated only when it looses focus, so we
+         * force updating if not focused. Lost focus issue appeared in (#15144)
          */
-        if (!(uidl
-                .getBooleanAttribute(TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS)
-                && getWidget().valueBeforeEdit != null && text
-                    .equals(getWidget().valueBeforeEdit))) {
+        if (!(Util.getFocusedElement() == getWidget().getElement())
+                || !uidl.getBooleanAttribute(TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS)
+                || getWidget().valueBeforeEdit == null
+                || !text.equals(getWidget().valueBeforeEdit)) {
             getWidget().updateFieldContent(text);
         }
 
diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPrompt.java b/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPrompt.java
new file mode 100644 (file)
index 0000000..9fe18f1
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.tests.components.textfield;
+
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.TextChangeEvent;
+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;
+
+@SuppressWarnings("serial")
+public class TextFieldEmptyingPrompt extends AbstractTestUI {
+
+    final TextField textField = new TextField();
+    final Label label = new Label();
+    final static String RANDOM_PROMPT = "Some prompt here";
+
+    @Override
+    public String getTestDescription() {
+        return "Type something, then erase it, then click on the button.<br>"
+                + "Input prompt should dissapear.<br>";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 15144;
+    }
+
+    @Override
+    protected void setup(VaadinRequest request) {
+
+        addComponent(label);
+
+        textField.setInputPrompt(RANDOM_PROMPT);
+        textField.addTextChangeListener(new FieldEvents.TextChangeListener() {
+
+            @Override
+            public void textChange(TextChangeEvent event) {
+                label.setValue("Textfield value: " + event.getText());
+            }
+        });
+        addComponent(textField);
+
+        Button button = new Button("Click To Remove Prompt");
+        button.addClickListener(new Button.ClickListener() {
+
+            @Override
+            public void buttonClick(ClickEvent event) {
+
+                textField.setInputPrompt("");
+            }
+        });
+        addComponent(button);
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPromptTest.java b/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPromptTest.java
new file mode 100644 (file)
index 0000000..f4fa5d0
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.textfield;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+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 TextFieldEmptyingPromptTest extends MultiBrowserTest {
+
+    private String RANDOM_INPUT = "Some input here";
+
+    private TextFieldElement textfield;
+    private LabelElement label;
+    private ButtonElement button;
+
+    @Test
+    public void testInputPrompt() throws InterruptedException {
+        openTestURL();
+
+        textfield = $(TextFieldElement.class).first();
+        label = $(LabelElement.class).get(1);
+        button = $(ButtonElement.class).first();
+
+        // Write on the TextField
+        writeOnTextField();
+
+        // Make sure a complete server communication cycle happened
+        waitServerUpdate("Textfield value: " + RANDOM_INPUT);
+
+        // Empty the TextField
+        emptyTextField();
+
+        // Click attempts to remove the prompt
+        button.click();
+
+        // Assert Prompt text disappeared
+        waitServerUpdateText("");
+    }
+
+    private void waitServerUpdate(final String expectedValue) {
+        waitUntil(new ExpectedCondition<Boolean>() {
+
+            @Override
+            public Boolean apply(WebDriver input) {
+                return label.getText().equals(expectedValue);
+            }
+
+            @Override
+            public String toString() {
+                // Timed out after 10 seconds waiting for ...
+                return "the server to get updated with the entered value: '"
+                        + expectedValue + "' (was: '" + label.getText() + "')";
+            }
+        });
+    }
+
+    private void waitServerUpdateText(final String expectedValue) {
+        waitUntil(new ExpectedCondition<Boolean>() {
+
+            @Override
+            public Boolean apply(WebDriver input) {
+                return textfield.getValue().equals(expectedValue);
+            }
+
+            @Override
+            public String toString() {
+                // Timed out after 10 seconds waiting for ...
+                return "the server to get updated with the entered value: '"
+                        + expectedValue + "' (was: '" + textfield.getValue()
+                        + "')";
+            }
+        });
+    }
+
+    private void writeOnTextField() {
+        textfield.sendKeys(RANDOM_INPUT);
+    }
+
+    private void emptyTextField() {
+        for (int i = 0; i < RANDOM_INPUT.length(); i++) {
+            textfield.sendKeys(Keys.BACK_SPACE);
+        }
+    }
+}