Browse Source

Ignore change btwn paints and force update unfocused TextField (#15144)

Change-Id: I0ddcea2a617fea00d707f7deaf155e98b9d6a832
tags/7.4.0.beta3
AMahdy AbdElAziz 9 years ago
parent
commit
21b554709f

+ 9
- 7
client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java View 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);
}


+ 72
- 0
uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPrompt.java View File

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

+ 104
- 0
uitest/src/com/vaadin/tests/components/textfield/TextFieldEmptyingPromptTest.java View File

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

Loading…
Cancel
Save