Skip to content

Commit 3a37fa2

Browse files
committed
fix(lib input-change-events): Support form elements outsde a form container.
Also support form elements which are outside of a form container. This allows pat-autosubmit to also work with form inputs which are bound to a form but not contained wiithin.
1 parent 92dc7f5 commit 3a37fa2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/lib/input-change-events.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,21 @@ const _ = {
3838
// We've been given an element that is not a form input. We
3939
// therefore assume that it's a container of form inputs and
4040
// register handlers for its children.
41-
$el.findInclusive(":input").each(_.registerHandlersForElement);
41+
for (const _el of $el[0].closest("form").elements) {
42+
// Search for all form elements, also those outside the form
43+
// container.
44+
_.registerHandlersForElement.bind(_el)();
45+
}
4246
}
4347
},
4448

4549
registerHandlersForElement() {
50+
let el_within_form = true;
51+
const $form = $(this.form);
52+
if (this.closest("form") !== this.form) {
53+
el_within_form = false;
54+
}
55+
4656
const $el = $(this);
4757
const isNumber = $el.is("input[type=number]");
4858
const isText = $el.is("input:text, input[type=search], textarea");
@@ -53,24 +63,24 @@ const _ = {
5363
if ("onkeyup" in window) {
5464
$el.on("keyup." + namespace, function () {
5565
log.debug("translating keyup");
56-
$el.trigger("input-change");
66+
(el_within_form ? $el : $form).trigger("input-change");
5767
});
5868
}
5969
}
6070
if (isText || isNumber) {
6171
$el.on("input." + namespace, function () {
6272
log.debug("translating input");
63-
$el.trigger("input-change");
73+
(el_within_form ? $el : $form).trigger("input-change");
6474
});
6575
} else {
6676
$el.on("change." + namespace, function () {
6777
log.debug("translating change");
68-
$el.trigger("input-change");
78+
(el_within_form ? $el : $form).trigger("input-change");
6979
});
7080
}
7181

7282
$el.on("blur", function () {
73-
$el.trigger("input-defocus");
83+
(el_within_form ? $el : $form).trigger("input-defocus");
7484
});
7585
},
7686

0 commit comments

Comments
 (0)