Skip to content

Commit

Permalink
Implementation of CSS pseudo classes :invalid and :valid improved (#338)
Browse files Browse the repository at this point in the history
Form.isValid() checks all form elements
  • Loading branch information
rbri committed Oct 17, 2023
1 parent 51103b9 commit 8421216
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<body>
<release version="3.7.0" date="October xx, 2023" description="Firefox 118, Chrome/Edge 118, Bugfixes, Documentation updates">
<action type="update" dev="rbri" issue="#338">
Implementation of CSS pseudo classes :invalid and :valid improved.
</action>
<action type="update" dev="rbri">
Form.isValid() checks all form elements.
</action>
<action type="update" dev="rbri">
WebClient documentation enhanced.
</action>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/htmlunit/css/CssStyleSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@
import org.htmlunit.html.DomText;
import org.htmlunit.html.HtmlCheckBoxInput;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlInput;
import org.htmlunit.html.HtmlLink;
import org.htmlunit.html.HtmlOption;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlRadioButtonInput;
import org.htmlunit.html.HtmlStyle;
import org.htmlunit.html.HtmlTextArea;
import org.htmlunit.html.ValidatableElement;
import org.htmlunit.javascript.host.css.MediaList;
import org.htmlunit.javascript.host.dom.Document;
import org.htmlunit.javascript.host.html.HTMLDocument;
Expand Down Expand Up @@ -870,10 +872,16 @@ private static boolean selectsPseudoClass(final BrowserVersion browserVersion,
return true;

case "valid":
return element instanceof HtmlElement && ((HtmlElement) element).isValid();
if (element instanceof HtmlForm || element instanceof ValidatableElement) {
return ((HtmlElement) element).isValid();
}
return false;

case "invalid":
return element instanceof HtmlElement && !((HtmlElement) element).isValid();
if (element instanceof HtmlForm || element instanceof ValidatableElement) {
return !((HtmlElement) element).isValid();
}
return false;

case "empty":
return isEmpty(element);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/htmlunit/html/HtmlForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,19 @@ public Page reset() {
return htmlPage;
}

/**
* {@inheritDoc}
*/
@Override
public boolean isValid() {
for (final HtmlElement element : getElements()) {
if (!element.isValid()) {
return false;
}
}
return super.isValid();
}

/**
* Returns a collection of elements that represent all the "submittable" elements in this form,
* assuming that the specified element is used to submit the form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,7 @@ public void pseudoRadioChecked() throws Exception {
@Test
@Alerts(DEFAULT = {"theform", "id3"},
IE = "id3") //minLength and maxLength not supported in IE
@HtmlUnitNYI(CHROME = "id3",
EDGE = "id3",
FF = "id3",
FF_ESR = "id3")
@HtmlUnitNYI(IE = {"theform", "id3"})
public void pseudoInvalid() throws Exception {
final String html = "<html><head>\n"
+ "<script>\n"
Expand Down Expand Up @@ -1095,11 +1092,6 @@ public void pseudoInvalid() throws Exception {
*/
@Test
@Alerts({"id1", "id2", "id4", "id5", "id6"})
@HtmlUnitNYI(CHROME = {"", "", "", "", "theform", "id1", "id2", "id4", "id5", "id6", "id7"},
EDGE = {"", "", "", "", "theform", "id1", "id2", "id4", "id5", "id6", "id7"},
FF = {"", "", "", "", "theform", "id1", "id2", "id4", "id5", "id6", "id7"},
FF_ESR = {"", "", "", "", "theform", "id1", "id2", "id4", "id5", "id6", "id7"},
IE = {"", "", "", "", "theform", "id1", "id2", "id4", "id5", "id6", "id7"})
public void pseudoValid() throws Exception {
final String html = "<html><head>\n"
+ "<script>\n"
Expand Down

0 comments on commit 8421216

Please sign in to comment.