diff options
author | AMahdy AbdElAziz <amahdy7@gmail.com> | 2015-01-07 15:01:28 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2015-01-21 11:04:19 +0200 |
commit | 513901091f8878d8b6b135d32b04091ed68f87b2 (patch) | |
tree | c19a83b6b4b4d126a4436d9c743e13d1e9cd0f6f | |
parent | 4e9c6a66b9c91404386af5c87bf733873874b16f (diff) | |
download | vaadin-framework-513901091f8878d8b6b135d32b04091ed68f87b2.tar.gz vaadin-framework-513901091f8878d8b6b135d32b04091ed68f87b2.zip |
Ignore change btwn paints and force update unfocused TextField (#15144)
Change-Id: I0ddcea2a617fea00d707f7deaf155e98b9d6a832
Conflicts:
client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java
3 files changed, 185 insertions, 7 deletions
diff --git a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java index 42b045005f..0d85e98ee3 100644 --- a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -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 que (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 index 0000000000..9fe18f131b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPrompt.java @@ -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 index 0000000000..f4fa5d0dc5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPromptTest.java @@ -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); + } + } +} |