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.javascript.host.html;
16
17 import org.htmlunit.html.DomElement;
18 import org.htmlunit.html.HtmlFieldSet;
19 import org.htmlunit.html.HtmlForm;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxFunction;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24 import org.htmlunit.javascript.configuration.JsxSetter;
25
26 /**
27 * The JavaScript object {@code HTMLFieldSetElement}.
28 *
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 */
32 @JsxClass(domClass = HtmlFieldSet.class)
33 public class HTMLFieldSetElement extends HTMLElement {
34
35 /**
36 * JavaScript constructor.
37 */
38 @Override
39 @JsxConstructor
40 public void jsConstructor() {
41 super.jsConstructor();
42 }
43
44 /**
45 * Returns the {@code name} attribute.
46 * @return the {@code name} attribute
47 */
48 @JsxGetter
49 @Override
50 public String getName() {
51 return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
52 }
53
54 /**
55 * Sets the {@code name} attribute.
56 * @param name the {@code name} attribute
57 */
58 @JsxSetter
59 @Override
60 public void setName(final String name) {
61 getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
62 }
63
64 /**
65 * Returns the value of the JavaScript {@code form} attribute.
66 *
67 * @return the value of the JavaScript {@code form} attribute
68 */
69 @JsxGetter
70 @Override
71 public HTMLFormElement getForm() {
72 final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
73 if (form == null) {
74 return null;
75 }
76 return (HTMLFormElement) getScriptableFor(form);
77 }
78
79 /**
80 * Checks whether the element has any constraints and whether it satisfies them.
81 * @return if the element is valid
82 */
83 @JsxFunction
84 public boolean checkValidity() {
85 return getDomNodeOrDie().isValid();
86 }
87
88 /**
89 * {@inheritDoc} Overridden to modify browser configurations.
90 */
91 @Override
92 @JsxGetter
93 public boolean isDisabled() {
94 return super.isDisabled();
95 }
96
97 /**
98 * {@inheritDoc} Overridden to modify browser configurations.
99 */
100 @Override
101 @JsxSetter
102 public void setDisabled(final boolean disabled) {
103 super.setDisabled(disabled);
104 }
105
106 /**
107 * @return a ValidityState with the validity states that this element is in.
108 */
109 @JsxGetter
110 public ValidityState getValidity() {
111 final ValidityState validityState = new ValidityState();
112 validityState.setPrototype(getPrototype(validityState.getClass()));
113 validityState.setParentScope(getParentScope());
114 validityState.setDomNode(getDomNodeOrDie());
115 return validityState;
116 }
117
118 /**
119 * @return whether the element is a candidate for constraint validation
120 */
121 @JsxGetter
122 public boolean isWillValidate() {
123 return ((HtmlFieldSet) getDomNodeOrDie()).willValidate();
124 }
125
126 /**
127 * Sets the custom validity message for the element to the specified message.
128 * @param message the new message
129 */
130 @JsxFunction
131 public void setCustomValidity(final String message) {
132 ((HtmlFieldSet) getDomNodeOrDie()).setCustomValidity(message);
133 }
134 }