* side value). <input> is updated only when it looses focus, so we
* force updating if not focused. Lost focus issue appeared in (#15144)
*/
- if (!(Util.getFocusedElement() == getWidget().getElement())
+ if (Util.getFocusedElement() != getWidget().getElement()
|| !uidl.getBooleanAttribute(TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS)
- || getWidget().valueBeforeEdit == null
- || !text.equals(getWidget().valueBeforeEdit)) {
+ || getWidget().valueBeforeEdit == null) {
getWidget().updateFieldContent(text);
}
selectionPosition = -1;
}
- if (hasListeners(TextChangeEvent.class)) {
- target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE,
- getTextChangeEventMode().toString());
- target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT,
- getTextChangeTimeout());
- if (lastKnownTextContent != null) {
- /*
- * The field has be repainted for some reason (e.g. caption,
- * size, stylename), but the value has not been changed since
- * the last text change event. Let the client side know about
- * the value the server side knows. Client side may then ignore
- * the actual value, depending on its state.
- */
- target.addAttribute(
- TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS,
- true);
- }
+ target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE,
+ getTextChangeEventMode().toString());
+ target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT,
+ getTextChangeTimeout());
+ if (lastKnownTextContent != null) {
+ /*
+ * The field has be repainted for some reason (e.g. caption, size,
+ * stylename), but the value has not been changed since the last
+ * text change event. Let the client side know about the value the
+ * server side knows. Client side may then ignore the actual value,
+ * depending on its state.
+ */
+ target.addAttribute(
+ TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS,
+ true);
}
-
}
@Override
--- /dev/null
+package com.vaadin.tests.components.textfield;
+
+import com.vaadin.event.FieldEvents;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.TextField;
+
+public class RemoveTextChangeListener extends AbstractTestUI {
+ @Override
+ protected void setup(VaadinRequest request) {
+ final TextField textfield = new TextField();
+
+ textfield.addTextChangeListener(new FieldEvents.TextChangeListener() {
+ @Override
+ public void textChange(FieldEvents.TextChangeEvent event) {
+ textfield.removeTextChangeListener(this);
+ }
+ });
+
+ addComponent(textfield);
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 16270;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Removing text change listener on text change event should not reset the input.";
+ }
+}
--- /dev/null
+package com.vaadin.tests.components.textfield;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class RemoveTextChangeListenerTest extends MultiBrowserTest {
+
+ @Test
+ public void serverValueIsUpdated() {
+ openTestURL();
+
+ TextFieldElement textfield = $(TextFieldElement.class).first();
+
+ textfield.sendKeys("f");
+
+ assertThat(textfield.getValue(), is("f"));
+ }
+
+}
\ No newline at end of file