1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.html;
16
17 /**
18 * An element that supports client side validation based on
19 * the Constraint validation API.
20 * see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation">
21 * https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation</a>
22 *
23 * @author Ronald Brill
24 */
25 public interface ValidatableElement {
26
27 /**
28 * @return whether the element is a candidate for constraint validation
29 */
30 boolean willValidate();
31
32 /**
33 * Sets the custom validity message for the element to the specified message.
34 * @param message the new message
35 */
36 void setCustomValidity(String message);
37
38 /**
39 * @return a boolean value boolean value that is true if the user
40 * has provided input that the browser is unable to convert.
41 */
42 default boolean hasBadInputValidityState() {
43 return false;
44 }
45
46 /**
47 * @return a boolean value indicating whether the element's custom validity message
48 * has been set to a non-empty string by calling the element's setCustomValidity() method.
49 */
50 boolean isCustomErrorValidityState();
51
52 /**
53 * @return true if the value does not match the specified pattern,
54 * and false if it does match.
55 * If true, the element matches the :invalid CSS pseudo-class
56 */
57 default boolean hasPatternMismatchValidityState() {
58 return false;
59 }
60
61 /**
62 * @return true if the value does not fit the rules determined by the step attribute
63 * (that is, it's not evenly divisible by the step value),
64 * or false if it does fit the step rule.
65 * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
66 */
67 default boolean isStepMismatchValidityState() {
68 return false;
69 }
70
71 /**
72 * @return true if the value is longer than the maximum length specified
73 * by the maxlength attribute, or false if it is shorter than or equal to the maximum.
74 * If true, the element matches the :invalid CSS pseudo-class
75 */
76 default boolean isTooLongValidityState() {
77 return false;
78 }
79
80 /**
81 * @return true if the value is shorter than the minimum length specified
82 * by the minlength attribute, or false if it is greater than or equal to the minimum.
83 * If true, the element matches the :invalid CSS pseudo-class
84 */
85 default boolean isTooShortValidityState() {
86 return false;
87 }
88
89 /**
90 * @return true if the value is not in the required syntax (when type is email or url),
91 * or false if the syntax is correct.
92 * If true, the element matches the :invalid CSS pseudo-class.
93 */
94 default boolean hasTypeMismatchValidityState() {
95 return false;
96 }
97
98 /**
99 * @return true if the value is greater than the maximum specified by the max attribute,
100 * or false if it is less than or equal to the maximum.
101 * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
102 */
103 default boolean hasRangeOverflowValidityState() {
104 return false;
105 }
106
107 /**
108 * @return true if the value is less than the minimum specified by the min attribute,
109 * or false if it is greater than or equal to the minimum.
110 * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
111 */
112 default boolean hasRangeUnderflowValidityState() {
113 return false;
114 }
115
116 /**
117 * @return true if the element meets all its validation constraints, and is therefore
118 * considered to be valid, or false if it fails any constraint.
119 * If true, the element matches the :valid CSS pseudo-class; the :invalid CSS pseudo-class otherwise.
120 */
121 boolean isValidValidityState();
122
123 /**
124 * @return true if the element has a required attribute, but no value, or false otherwise.
125 * If true, the element matches the :invalid CSS pseudo-class.
126 */
127 default boolean isValueMissingValidityState() {
128 return false;
129 }
130 }