Skip to content

Commit

Permalink
refactor: deprecate ClientValidatedEvent and HasClientValidation (#6795)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Nov 18, 2024
1 parent 7a97cd8 commit 61e507d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.DomEvent;
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.data.binder.HasValidator;
import com.vaadin.flow.data.binder.ValidationStatusChangeEvent;
import com.vaadin.flow.shared.Registration;

/**
* Mixin interface for subscribing to the client-side `validated` event from a
* component.
*
* @deprecated Since 24.6, this interface is no longer supported. Consider
* {@link HasValidation} or {@link HasValidator} as an alternative.
*/
@Deprecated
public interface HasClientValidation extends Serializable {
/**
* Adds a listener for the {@code validated} event fired by the web
Expand All @@ -37,7 +44,11 @@ public interface HasClientValidation extends Serializable {
* @param listener
* the listener, not null.
* @return a {@link Registration} for removing the event listener.
* @deprecated Since 24.6, this event is no longer supported. Consider
* subscribing to {@link ValidationStatusChangeEvent} to get
* notified when the user enters input that cannot be parsed.
*/
@Deprecated
default Registration addClientValidatedEventListener(
ComponentEventListener<ClientValidatedEvent> listener) {
return ComponentUtil.addListener((Component) this,
Expand All @@ -47,8 +58,13 @@ default Registration addClientValidatedEventListener(
/**
* An event fired by the web component whenever it is validated on the
* client-side.
*
* @deprecated Since 24.6, this event is no longer supported. Consider
* subscribing to {@link ValidationStatusChangeEvent} to get
* notified when the user enters input that cannot be parsed.
*/
@DomEvent("validated")
@Deprecated
public static class ClientValidatedEvent extends ComponentEvent<Component> {

private final boolean valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.shared.HasClientValidation.ClientValidatedEvent;
import com.vaadin.flow.dom.DomEvent;
import com.vaadin.flow.internal.nodefeature.ElementListenerMap;

import elemental.json.Json;

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

@Test
public void setRequired_setManualValidation_fireUnparsableChangeEvent_noValidation() {
testField.setRequiredIndicatorVisible(true);
testField.setManualValidation(true);

fireUnparsableChangeDomEvent();
Assert.assertFalse(testField.isInvalid());
}

@Test
public void setRequired_setManualValidation_fireClientValidatedEvent_noValidation() {
testField.setRequiredIndicatorVisible(true);
Expand Down Expand Up @@ -82,4 +95,11 @@ public void setInvalid_isInvalid() {
}

protected abstract C createTestField();

private void fireUnparsableChangeDomEvent() {
DomEvent unparsableChangeDomEvent = new DomEvent(testField.getElement(),
"unparsable-change", Json.createObject());
testField.getElement().getNode().getFeature(ElementListenerMap.class)
.fireEvent(unparsableChangeDomEvent);
}
}

0 comments on commit 61e507d

Please sign in to comment.