Skip to content

Commit 61e507d

Browse files
authored
refactor: deprecate ClientValidatedEvent and HasClientValidation (#6795)
1 parent 7a97cd8 commit 61e507d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

vaadin-flow-components-shared-parent/vaadin-flow-components-base/src/main/java/com/vaadin/flow/component/shared/HasClientValidation.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
import com.vaadin.flow.component.ComponentUtil;
2424
import com.vaadin.flow.component.DomEvent;
2525
import com.vaadin.flow.component.EventData;
26+
import com.vaadin.flow.component.HasValidation;
27+
import com.vaadin.flow.data.binder.HasValidator;
28+
import com.vaadin.flow.data.binder.ValidationStatusChangeEvent;
2629
import com.vaadin.flow.shared.Registration;
2730

2831
/**
2932
* Mixin interface for subscribing to the client-side `validated` event from a
3033
* component.
34+
*
35+
* @deprecated Since 24.6, this interface is no longer supported. Consider
36+
* {@link HasValidation} or {@link HasValidator} as an alternative.
3137
*/
38+
@Deprecated
3239
public interface HasClientValidation extends Serializable {
3340
/**
3441
* Adds a listener for the {@code validated} event fired by the web
@@ -37,7 +44,11 @@ public interface HasClientValidation extends Serializable {
3744
* @param listener
3845
* the listener, not null.
3946
* @return a {@link Registration} for removing the event listener.
47+
* @deprecated Since 24.6, this event is no longer supported. Consider
48+
* subscribing to {@link ValidationStatusChangeEvent} to get
49+
* notified when the user enters input that cannot be parsed.
4050
*/
51+
@Deprecated
4152
default Registration addClientValidatedEventListener(
4253
ComponentEventListener<ClientValidatedEvent> listener) {
4354
return ComponentUtil.addListener((Component) this,
@@ -47,8 +58,13 @@ default Registration addClientValidatedEventListener(
4758
/**
4859
* An event fired by the web component whenever it is validated on the
4960
* client-side.
61+
*
62+
* @deprecated Since 24.6, this event is no longer supported. Consider
63+
* subscribing to {@link ValidationStatusChangeEvent} to get
64+
* notified when the user enters input that cannot be parsed.
5065
*/
5166
@DomEvent("validated")
67+
@Deprecated
5268
public static class ClientValidatedEvent extends ComponentEvent<Component> {
5369

5470
private final boolean valid;

vaadin-flow-components-shared-parent/vaadin-flow-components-test-util/src/main/java/com/vaadin/tests/validation/AbstractBasicValidationTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import com.vaadin.flow.component.ComponentUtil;
2525
import com.vaadin.flow.component.HasValidation;
2626
import com.vaadin.flow.component.shared.HasClientValidation.ClientValidatedEvent;
27+
import com.vaadin.flow.dom.DomEvent;
28+
import com.vaadin.flow.internal.nodefeature.ElementListenerMap;
29+
30+
import elemental.json.Json;
2731

2832
/**
2933
* An abstract class that provides tests verifying that a component correctly
@@ -47,6 +51,15 @@ public void setRequired_setManualValidation_fireValueChangeEvent_noValidation()
4751
Assert.assertFalse(testField.isInvalid());
4852
}
4953

54+
@Test
55+
public void setRequired_setManualValidation_fireUnparsableChangeEvent_noValidation() {
56+
testField.setRequiredIndicatorVisible(true);
57+
testField.setManualValidation(true);
58+
59+
fireUnparsableChangeDomEvent();
60+
Assert.assertFalse(testField.isInvalid());
61+
}
62+
5063
@Test
5164
public void setRequired_setManualValidation_fireClientValidatedEvent_noValidation() {
5265
testField.setRequiredIndicatorVisible(true);
@@ -82,4 +95,11 @@ public void setInvalid_isInvalid() {
8295
}
8396

8497
protected abstract C createTestField();
98+
99+
private void fireUnparsableChangeDomEvent() {
100+
DomEvent unparsableChangeDomEvent = new DomEvent(testField.getElement(),
101+
"unparsable-change", Json.createObject());
102+
testField.getElement().getNode().getFeature(ElementListenerMap.class)
103+
.fireEvent(unparsableChangeDomEvent);
104+
}
85105
}

0 commit comments

Comments
 (0)