Skip to content

Commit b04cabb

Browse files
duonglaiquangrbri
authored andcommitted
HtmlElement: fix a bug where input event not fired with type=email/url/date/time
1 parent 6ca1db9 commit b04cabb

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,8 @@ private Page type(final char c, final boolean lastType)
592592
}
593593

594594
final WebClient webClient = page.getWebClient();
595-
if (this instanceof HtmlTextInput
596-
|| this instanceof HtmlTextArea
597-
|| this instanceof HtmlTelInput
598-
|| this instanceof HtmlNumberInput
599-
|| this instanceof HtmlSearchInput
600-
|| this instanceof HtmlPasswordInput) {
595+
if (this instanceof HtmlSelectableTextInput
596+
|| this instanceof HtmlTextArea) {
601597
fireEvent(new KeyboardEvent(this, Event.TYPE_INPUT, c,
602598
shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_));
603599
}

src/test/java/org/htmlunit/html/HtmlElementTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,4 +1269,27 @@ public void acceptChar() throws Exception {
12691269
input.type(value);
12701270
assertEquals(value, input.getValue());
12711271
}
1272+
1273+
/**
1274+
* @throws Exception if an error occurs
1275+
*/
1276+
@Test
1277+
public void typeFiresInputEvent() throws Exception {
1278+
final String[] types = {"text", "tel", "number", "search", "password", "email", "url", "date", "time"};
1279+
1280+
for (final String type : types) {
1281+
final String html = DOCTYPE_HTML
1282+
+ "<html><body>\n"
1283+
+ "<input type='" + type + "' id='t'>\n"
1284+
+ "<script>\n"
1285+
+ " document.getElementById('t').addEventListener('input', function() {\n"
1286+
+ " document.title += 'input';\n"
1287+
+ " });\n"
1288+
+ "</script>\n"
1289+
+ "</body></html>";
1290+
final HtmlPage page = loadPage(html);
1291+
page.getHtmlElementById("t").type("ab");
1292+
assertEquals("input event for type=" + type, "inputinput", page.getTitleText());
1293+
}
1294+
}
12721295
}

0 commit comments

Comments
 (0)