View Javadoc
1   /*
2    * Copyright (c) 2002-2026 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   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldSetElement">MDN Documentation</a>
33   */
34  @JsxClass(domClass = HtmlFieldSet.class)
35  public class HTMLFieldSetElement extends HTMLElement {
36  
37      /**
38       * JavaScript constructor.
39       */
40      @Override
41      @JsxConstructor
42      public void jsConstructor() {
43          super.jsConstructor();
44      }
45  
46      /**
47       * Returns the {@code name} attribute.
48       * @return the {@code name} attribute
49       */
50      @JsxGetter
51      @Override
52      public String getName() {
53          return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
54      }
55  
56      /**
57       * Sets the {@code name} attribute.
58       * @param name the {@code name} attribute value
59       */
60      @JsxSetter
61      @Override
62      public void setName(final String name) {
63          getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
64      }
65  
66      /**
67       * Returns the value of the JavaScript {@code form} attribute.
68       *
69       * @return the value of the JavaScript {@code form} attribute
70       */
71      @JsxGetter
72      @Override
73      public HTMLFormElement getForm() {
74          final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
75          if (form == null) {
76              return null;
77          }
78          return (HTMLFormElement) getScriptableFor(form);
79      }
80  
81      /**
82       * Checks whether the element has any constraints and whether it satisfies them.
83       * @return {@code true} if the element is valid
84       */
85      @JsxFunction
86      public boolean checkValidity() {
87          return getDomNodeOrDie().isValid();
88      }
89  
90      /**
91       * {@inheritDoc} Overridden to modify browser configurations.
92       */
93      @Override
94      @JsxGetter
95      public boolean isDisabled() {
96          return super.isDisabled();
97      }
98  
99      /**
100      * {@inheritDoc} Overridden to modify browser configurations.
101      */
102     @Override
103     @JsxSetter
104     public void setDisabled(final boolean disabled) {
105         super.setDisabled(disabled);
106     }
107 
108     /**
109      * Returns a {@link ValidityState} object representing the validity states of this element.
110      * @return a {@link ValidityState} object representing the validity states of this element
111      */
112     @JsxGetter
113     public ValidityState getValidity() {
114         final ValidityState validityState = new ValidityState();
115         validityState.setPrototype(getPrototype(validityState.getClass()));
116         validityState.setParentScope(getParentScope());
117         validityState.setDomNode(getDomNodeOrDie());
118         return validityState;
119     }
120 
121     /**
122      * Returns whether the element is a candidate for constraint validation.
123      * @return whether the element is a candidate for constraint validation
124      */
125     @JsxGetter
126     public boolean isWillValidate() {
127         return ((HtmlFieldSet) getDomNodeOrDie()).willValidate();
128     }
129 
130     /**
131      * Sets the custom validity message for the element to the specified message.
132      * @param message the new message
133      */
134     @JsxFunction
135     public void setCustomValidity(final String message) {
136         ((HtmlFieldSet) getDomNodeOrDie()).setCustomValidity(message);
137     }
138 }