Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deprecate ClientValidatedEvent and HasClientValidation #6795

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}