added the closest and trigger events out of the rules

This commit is contained in:
Nivanka Fonseka 2023-04-27 10:51:04 +12:00
parent ccd028c22d
commit 82e6588cd9

View File

@ -207,8 +207,7 @@ class UserDefinedFormController extends PageController
$rules .= $this->buildWatchJS($watch);
}
// Only add customScript if $default or $rules is defined
if ($rules) {
// add the custom scripts thats used by the steps.
Requirements::customScript(<<<JS
function closest(el, sel) {
while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el,sel)));
@ -223,6 +222,14 @@ class UserDefinedFormController extends PageController
element.dispatchEvent(event);
}
window.triggerDispatchEvent = triggerDispatchEvent;
JS
);
// Only add customScript if $default or $rules is defined
if ($rules) {
Requirements::customScript(<<<JS
document.addEventListener("DOMContentLoaded", function() {
var form = document.querySelector('form.userform');
if (form) {