Skip to content

Commit 00324ac

Browse files
committed
Input type image returns false for willValidate
1 parent 5e471bb commit 00324ac

4 files changed

Lines changed: 232 additions & 8 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="5.0.0" date="April 31, 2026" description="jdk17, Firefox 149, Chrome 147, Bugfixes">
11+
<action type="fix" dev="rbri">
12+
Input type image returns false for willValidate.
13+
</action>
1114
<action type="fix" dev="rbri">
1215
XMLHttpRequest adds the origin header to patch requests.
1316
</action>

src/main/java/org/htmlunit/html/HtmlImageInput.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ public void setDefaultValue(final String defaultValue) {
186186
setRawValue(defaultValue);
187187
}
188188

189+
/**
190+
* {@inheritDoc}
191+
*/
192+
@Override
193+
public boolean willValidate() {
194+
return false;
195+
}
196+
189197
/**
190198
* {@inheritDoc}
191199
*/

src/main/java/org/htmlunit/html/HtmlSelect.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515
package org.htmlunit.html;
1616

17-
import static org.htmlunit.BrowserVersionFeatures.HTMLSELECT_WILL_VALIDATE_IGNORES_READONLY;
18-
1917
import java.util.ArrayList;
2018
import java.util.Collections;
2119
import java.util.List;
@@ -737,7 +735,7 @@ protected boolean isRequiredSupported() {
737735
*/
738736
@Override
739737
public boolean willValidate() {
740-
return !isDisabled() && (hasFeature(HTMLSELECT_WILL_VALIDATE_IGNORES_READONLY) || !isReadOnly());
738+
return !isDisabled();
741739
}
742740

743741
/**

src/test/java/org/htmlunit/javascript/host/html/HTMLInputElementTest.java

Lines changed: 220 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,221 @@ public void clear() throws Exception {
24632463
@Test
24642464
@Alerts({"true", "false", "true", "false", "true"})
24652465
public void willValidate() throws Exception {
2466+
willValidate("");
2467+
}
2468+
2469+
/**
2470+
* @throws Exception if an error occurs
2471+
*/
2472+
@Test
2473+
@Alerts({"false", "false", "false", "false", "false"})
2474+
public void willValidateButton() throws Exception {
2475+
willValidate("type='button'");
2476+
}
2477+
2478+
/**
2479+
* @throws Exception if an error occurs
2480+
*/
2481+
@Test
2482+
@Alerts({"true", "false", "true", "false", "true"})
2483+
public void willValidateCheckbox() throws Exception {
2484+
willValidate("type='checkbox'");
2485+
}
2486+
2487+
/**
2488+
* @throws Exception if an error occurs
2489+
*/
2490+
@Test
2491+
@Alerts({"true", "false", "true", "false", "true"})
2492+
public void willValidateColor() throws Exception {
2493+
willValidate("type='color'");
2494+
}
2495+
2496+
/**
2497+
* @throws Exception if an error occurs
2498+
*/
2499+
@Test
2500+
@Alerts({"true", "false", "true", "false", "true"})
2501+
public void willValidateDate() throws Exception {
2502+
willValidate("type='date'");
2503+
}
2504+
2505+
/**
2506+
* @throws Exception if an error occurs
2507+
*/
2508+
@Test
2509+
@Alerts({"true", "false", "true", "false", "true"})
2510+
public void willValidateDatetime() throws Exception {
2511+
willValidate("type='datetime'");
2512+
}
2513+
2514+
/**
2515+
* @throws Exception if an error occurs
2516+
*/
2517+
@Test
2518+
@Alerts({"true", "false", "true", "false", "true"})
2519+
public void willValidateDatetimelocal() throws Exception {
2520+
willValidate("type='datetime-local'");
2521+
}
2522+
2523+
/**
2524+
* @throws Exception if an error occurs
2525+
*/
2526+
@Test
2527+
@Alerts({"true", "false", "true", "false", "true"})
2528+
public void willValidateEmail() throws Exception {
2529+
willValidate("type='email'");
2530+
}
2531+
2532+
/**
2533+
* @throws Exception if an error occurs
2534+
*/
2535+
@Test
2536+
@Alerts({"true", "false", "true", "false", "true"})
2537+
public void willValidateFile() throws Exception {
2538+
willValidate("type='file'");
2539+
}
2540+
2541+
/**
2542+
* @throws Exception if an error occurs
2543+
*/
2544+
@Test
2545+
@Alerts({"false", "false", "false", "false", "false"})
2546+
public void willValidateHidden() throws Exception {
2547+
willValidate("type='hidden'");
2548+
}
2549+
2550+
/**
2551+
* @throws Exception if an error occurs
2552+
*/
2553+
@Test
2554+
@Alerts(DEFAULT = {"false", "false", "false", "false", "false"},
2555+
FF = {"true", "false", "true", "false", "true"},
2556+
FF_ESR = {"true", "false", "true", "false", "true"})
2557+
@HtmlUnitNYI(FF = {"false", "false", "false", "false", "false"},
2558+
FF_ESR = {"false", "false", "false", "false", "false"})
2559+
public void willValidateImage() throws Exception {
2560+
willValidate("type='image'");
2561+
}
2562+
2563+
/**
2564+
* @throws Exception if an error occurs
2565+
*/
2566+
@Test
2567+
@Alerts({"true", "false", "true", "false", "true"})
2568+
public void willValidateMonth() throws Exception {
2569+
willValidate("type='month'");
2570+
}
2571+
2572+
/**
2573+
* @throws Exception if an error occurs
2574+
*/
2575+
@Test
2576+
@Alerts({"true", "false", "true", "false", "true"})
2577+
public void willValidateNumber() throws Exception {
2578+
willValidate("type='number'");
2579+
}
2580+
2581+
/**
2582+
* @throws Exception if an error occurs
2583+
*/
2584+
@Test
2585+
@Alerts({"true", "false", "true", "false", "true"})
2586+
public void willValidatePassword() throws Exception {
2587+
willValidate("type='password'");
2588+
}
2589+
2590+
/**
2591+
* @throws Exception if an error occurs
2592+
*/
2593+
@Test
2594+
@Alerts({"true", "false", "true", "false", "true"})
2595+
public void willValidateRadio() throws Exception {
2596+
willValidate("type='radio'");
2597+
}
2598+
2599+
/**
2600+
* @throws Exception if an error occurs
2601+
*/
2602+
@Test
2603+
@Alerts({"true", "false", "true", "false", "true"})
2604+
public void willValidateRange() throws Exception {
2605+
willValidate("type='range'");
2606+
}
2607+
2608+
/**
2609+
* @throws Exception if an error occurs
2610+
*/
2611+
@Test
2612+
@Alerts({"false", "false", "false", "false", "false"})
2613+
public void willValidateReset() throws Exception {
2614+
willValidate("type='reset'");
2615+
}
2616+
2617+
/**
2618+
* @throws Exception if an error occurs
2619+
*/
2620+
@Test
2621+
@Alerts({"true", "false", "true", "false", "true"})
2622+
public void willValidateSearch() throws Exception {
2623+
willValidate("type='search'");
2624+
}
2625+
2626+
/**
2627+
* @throws Exception if an error occurs
2628+
*/
2629+
@Test
2630+
@Alerts({"true", "false", "true", "false", "true"})
2631+
public void willValidateSubmit() throws Exception {
2632+
willValidate("type='submit'");
2633+
}
2634+
2635+
/**
2636+
* @throws Exception if an error occurs
2637+
*/
2638+
@Test
2639+
@Alerts({"true", "false", "true", "false", "true"})
2640+
public void willValidateTel() throws Exception {
2641+
willValidate("type='tel'");
2642+
}
2643+
2644+
/**
2645+
* @throws Exception if an error occurs
2646+
*/
2647+
@Test
2648+
@Alerts({"true", "false", "true", "false", "true"})
2649+
public void willValidateText() throws Exception {
2650+
willValidate("type='text'");
2651+
}
2652+
2653+
/**
2654+
* @throws Exception if an error occurs
2655+
*/
2656+
@Test
2657+
@Alerts({"true", "false", "true", "false", "true"})
2658+
public void willValidateTime() throws Exception {
2659+
willValidate("type='time'");
2660+
}
2661+
2662+
/**
2663+
* @throws Exception if an error occurs
2664+
*/
2665+
@Test
2666+
@Alerts({"true", "false", "true", "false", "true"})
2667+
public void willValidateUrl() throws Exception {
2668+
willValidate("type='url'");
2669+
}
2670+
2671+
/**
2672+
* @throws Exception if an error occurs
2673+
*/
2674+
@Test
2675+
@Alerts({"true", "false", "true", "false", "true"})
2676+
public void willValidateWeek() throws Exception {
2677+
willValidate("type='week'");
2678+
}
2679+
2680+
private void willValidate(final String type) throws Exception {
24662681
final String html = DOCTYPE_HTML
24672682
+ "<html><head>\n"
24682683
+ " <script>\n"
@@ -2478,11 +2693,11 @@ public void willValidate() throws Exception {
24782693
+ "</head>\n"
24792694
+ "<body onload='test()'>\n"
24802695
+ " <form>\n"
2481-
+ " <input id='i1'>\n"
2482-
+ " <input id='i2' disabled>\n"
2483-
+ " <input id='i3' hidden>\n"
2484-
+ " <input id='i4' readonly>\n"
2485-
+ " <input id='i5' style='display: none'>\n"
2696+
+ " <input id='i1' " + type + ">\n"
2697+
+ " <input id='i2' " + type + "disabled>\n"
2698+
+ " <input id='i3' " + type + "hidden>\n"
2699+
+ " <input id='i4' " + type + "readonly>\n"
2700+
+ " <input id='i5' " + type + "style='display: none'>\n"
24862701
+ " </form>\n"
24872702
+ "</body></html>";
24882703

0 commit comments

Comments
 (0)