mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
added the closest and trigger events out of the rules
This commit is contained in:
parent
ccd028c22d
commit
82e6588cd9
@ -207,22 +207,29 @@ class UserDefinedFormController extends PageController
|
||||
$rules .= $this->buildWatchJS($watch);
|
||||
}
|
||||
|
||||
// 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)));
|
||||
return el;
|
||||
}
|
||||
window.closest = closest;
|
||||
|
||||
function triggerDispatchEvent(element, eventName, arg) {
|
||||
const event = new CustomEvent(eventName, {
|
||||
detail: arg
|
||||
});
|
||||
element.dispatchEvent(event);
|
||||
}
|
||||
window.triggerDispatchEvent = triggerDispatchEvent;
|
||||
JS
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Only add customScript if $default or $rules is defined
|
||||
if ($rules) {
|
||||
Requirements::customScript(<<<JS
|
||||
function closest(el, sel) {
|
||||
while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el,sel)));
|
||||
return el;
|
||||
}
|
||||
window.closest = closest;
|
||||
|
||||
function triggerDispatchEvent(element, eventName, arg) {
|
||||
const event = new CustomEvent(eventName, {
|
||||
detail: arg
|
||||
});
|
||||
element.dispatchEvent(event);
|
||||
}
|
||||
window.triggerDispatchEvent = triggerDispatchEvent;
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var form = document.querySelector('form.userform');
|
||||
if (form) {
|
||||
|
Loading…
Reference in New Issue
Block a user