Skip to content

Commit 4505e47

Browse files
ugur-vaadinvursen
andauthored
fix: add manual validation property to custom field (#7567)
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
1 parent a1ec8e5 commit 4505e47

6 files changed

Lines changed: 54 additions & 97 deletions

File tree

‎vaadin-custom-field-flow-parent/vaadin-custom-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/customfield/tests/ValidationPage.java‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ public ValidationPage() {
3333
});
3434
setInvalid.setId("set-invalid");
3535

36-
NativeButton attach = new NativeButton("Attach", e -> {
37-
add(customField);
38-
});
39-
attach.setId("attach");
40-
41-
NativeButton detach = new NativeButton("Detach", e -> {
42-
remove(customField);
43-
});
44-
detach.setId("detach");
45-
4636
Span logOutput = new Span();
4737
logOutput.setId("log-output");
4838
NativeButton logInvalidState = new NativeButton("Log Invalid State",
@@ -52,7 +42,7 @@ public ValidationPage() {
5242
logInvalidState.setId("log-invalid-state");
5343

5444
add(customField);
55-
add(new Div(setInvalid, attach, detach, logInvalidState, logOutput));
45+
add(new Div(setInvalid, logInvalidState, logOutput));
5646
}
5747

5848
private class MyField extends CustomField<Integer> {

‎vaadin-custom-field-flow-parent/vaadin-custom-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/customfield/tests/ValidationIT.java‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class ValidationIT extends AbstractComponentIT {
2929

3030
private CustomFieldElement customField;
3131
private TestBenchElement setInvalid;
32-
private TestBenchElement attach;
33-
private TestBenchElement detach;
3432
private TestBenchElement logInvalidState;
3533
private TestBenchElement logOutput;
3634

@@ -40,33 +38,10 @@ public void init() {
4038

4139
customField = $(CustomFieldElement.class).waitForFirst();
4240
setInvalid = $("button").id("set-invalid");
43-
attach = $("button").id("attach");
44-
detach = $("button").id("detach");
4541
logInvalidState = $("button").id("log-invalid-state");
4642
logOutput = $("span").id("log-output");
4743
}
4844

49-
@Test
50-
public void overridesClientValidation() {
51-
setInvalid.click();
52-
53-
executeScript("arguments[0].validate()", customField);
54-
55-
Assert.assertEquals(true, customField.isInvalid());
56-
}
57-
58-
@Test
59-
public void detach_reattach_overridesClientValidation() {
60-
setInvalid.click();
61-
detach.click();
62-
attach.click();
63-
64-
customField = $(CustomFieldElement.class).waitForFirst();
65-
executeScript("arguments[0].validate()", customField);
66-
67-
Assert.assertEquals(true, customField.isInvalid());
68-
}
69-
7045
@Test
7146
public void changeInvalidOnClient_notSynchronizedToServer() {
7247
setInvalid.click();

‎vaadin-custom-field-flow-parent/vaadin-custom-field-flow/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
<artifactId>vaadin-flow-components-base</artifactId>
2727
<version>${project.version}</version>
2828
</dependency>
29+
<dependency>
30+
<groupId>com.vaadin</groupId>
31+
<artifactId>vaadin-flow-components-test-util</artifactId>
32+
<version>${project.version}</version>
33+
<scope>test</scope>
34+
</dependency>
2935
<dependency>
3036
<groupId>jakarta.platform</groupId>
3137
<artifactId>jakarta.jakartaee-web-api</artifactId>

‎vaadin-custom-field-flow-parent/vaadin-custom-field-flow/src/main/java/com/vaadin/flow/component/customfield/CustomField.java‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.slf4j.LoggerFactory;
2323

2424
import com.vaadin.flow.component.AbstractField;
25-
import com.vaadin.flow.component.AttachEvent;
2625
import com.vaadin.flow.component.Component;
2726
import com.vaadin.flow.component.Focusable;
2827
import com.vaadin.flow.component.HasTheme;
@@ -73,13 +72,7 @@ public CustomField(T defaultValue) {
7372
super(defaultValue);
7473
// Force a value update when the change event generated
7574
getElement().addEventListener("change", e -> this.updateValue());
76-
}
77-
78-
@Override
79-
protected void onAttach(AttachEvent attachEvent) {
80-
super.onAttach(attachEvent);
81-
82-
FieldValidationUtil.disableClientValidation(this);
75+
getElement().setProperty("manualValidation", true);
8376
}
8477

8578
/**

‎vaadin-custom-field-flow-parent/vaadin-custom-field-flow/src/main/java/com/vaadin/flow/component/customfield/FieldValidationUtil.java‎

Lines changed: 0 additions & 53 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2000-2025 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.component.customfield.validation;
17+
18+
import com.vaadin.flow.component.customfield.CustomField;
19+
import com.vaadin.flow.component.html.Input;
20+
import com.vaadin.tests.validation.AbstractBasicValidationTest;
21+
22+
public class BasicValidationTest
23+
extends AbstractBasicValidationTest<CustomField<String>, String> {
24+
class TestCustomField extends CustomField<String> {
25+
private Input input = new Input();
26+
27+
public TestCustomField() {
28+
add(input);
29+
}
30+
31+
@Override
32+
protected String generateModelValue() {
33+
return input.getValue();
34+
}
35+
36+
@Override
37+
protected void setPresentationValue(String newPresentationValue) {
38+
input.setValue(newPresentationValue);
39+
}
40+
};
41+
42+
@Override
43+
protected CustomField<String> createTestField() {
44+
return new TestCustomField();
45+
}
46+
}

0 commit comments

Comments
 (0)