-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat: integrate client-side validation into TextField #3429
Conversation
71c7794
to
95f8f77
Compare
721529d
to
b765d15
Compare
Some ITs have failed which is apparently caused by the fact that we don't trigger the binder validation on the Scenario:
|
I actually encountered a more heavy challenge which is that the Example: textField = new TextField();
textField.setValue("Some not empty value");
textField.setInvalid(true);
add(textField) What happens here is Polymer triggers value observers (because of the provided initial value) during the web component's initialization which subsequently triggers a I'm trying to fix that in the web components. |
a40c5b1
to
b192ffb
Compare
@@ -81,6 +83,8 @@ private TextField(boolean isInitialValueOptional) { | |||
setValueChangeMode(ValueChangeMode.ON_CHANGE); | |||
|
|||
addValueChangeListener(e -> validate()); | |||
|
|||
addClientValidatedEventListener(e -> validate()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still one missing piece, which is to fire the ValidationStatusChangeEvent
when the client side validation changes. Testing how it works, it seems that once the event is dispatched, the binder will take the validation status sent on the event to set the component is valid/invalid. So, the getDefaultValidator()
is not called.
The thing I am still thinking about is how the validate
method comes into play here. It needs to be called so that the component being used without binder will get the invalid state correctly set. But when binder is being used, we would probably need to call getValidationSupport().isInvalid(getValue())
to get the validation result and send it to binder with the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. My first impression of ValidationStatusChangeEventListener
was that we will need to subscribe the binder to ClientValidatedEvent
by adding ValidationStatusChangeEventListener
for ClientValidatedEvent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it seems that the way it should work is:
ValueChange
triggers constraint validation and then binder validation (this is already done).ClientValidated
triggers constraint validation and then binder validation by invokingValidationStatusChangeEventListener
listeners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually had a wrong assumption here:
So, the getDefaultValidator() is not called.
My mistake was because I placed the breakpoint on the method body instead of the lambda's. What I can understand now is:
- Client side validation fires
validated
event - Flow component listens the event and fires
ValidationStatusChangeEventListener
- Binder listens to this event and calls its
validate()
method - Eventually,
validate()
method will call the lambda created ongetDefaultValidator()
. - Component's
checkValidity()
method is called.
ae90842
to
b33b4fc
Compare
50cb675
to
40edcd9
Compare
The build succeeded. I think the only remaining thing now is to put changes behind a feature flag and choose between |
f59b6fe
to
22fbacb
Compare
return addClientValidatedEventListener(event -> { | ||
listener.validationStatusChanged( | ||
new ValidationStatusChangeEvent<String>(this, | ||
!isInvalid())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of the second parameter of ValidationStatusChangeEvent
is not clear to me given that it is not used anywhere.
5757145
to
4bc2dac
Compare
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
This ticket/PR has been released with Vaadin 23.2.0. |
Description
HasClientValidation
.ClientValidationUtil
.ValidationStatusChangeEventListener
.validated
event.validated
event.TextField
to valid.The integration tests are implemented as abstract classes so that they can be reused later for
NumberField
,PasswordField
, and so on.Depends on
Part of vaadin/platform#3066
Type of change
Checklist