wip handle custom form submit

This commit is contained in:
asus
2024-03-14 01:18:31 +01:00
parent 12de8ee12f
commit 2f4a5bb9ef
16 changed files with 485 additions and 145 deletions

View File

@@ -0,0 +1,24 @@
/*
cipf_admin_activate_prof_form
*/
function admin_activate_form_submit_prevent_CIPF() {
let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form');
console.log("form:");
console.log(form_activate_prof);
if (form_activate_prof === null)
return;
function handle_form(event) {
event.preventDefault();
let form_data = new FormData(event.target);
for (var pair of form_data.entries()) {
console.log(pair[0]+ ': ' + pair[1]);
}
}
form_activate_prof.addEventListener('submit', handle_form);
}
admin_activate_form_submit_prevent_CIPF();

View File

@@ -1,66 +1,71 @@
/*
* finds the input:checked in the element .calculate_field
* and trigger the event 'change' on it
* - this event 'change' is added by form builder in divi-form-calc-min.js :
* $(document).on(
* 'change',
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
* function () {
* ...
* }
* );
*
*/
function trigger_change_CIPF(element) {
/*
* jquery version
*
let inputs = $(element).find('input:checked');
inputs.trigger('change');
*/
function patch_form_calculation_CIPF() {
let form_calculation = document.querySelector('form.fb_form.multistep');
if (form_calculation === null)
return;
/*
* js version
* finds the input:checked in the element .calculate_field
* and trigger the event 'change' on it
* - this event 'change' is added by form builder in divi-form-calc-min.js :
* $(document).on(
* 'change',
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
* function () {
* ...
* }
* );
*
*/
let inputs = element.querySelectorAll('input:checked');
// loop through inputs and trigger 'change' event on each
inputs.forEach(function(input) {
// Triggering 'change' event
let change_event = new Event('change', {
bubbles: true,
cancelable: true,
function trigger_change(element) {
/*
* jquery version
*
let inputs = $(element).find('input:checked');
inputs.trigger('change');
*/
/*
* js version
*
*/
let inputs = element.querySelectorAll('input:checked');
// loop through inputs and trigger 'change' event on each
inputs.forEach(function(input) {
// Triggering 'change' event
let change_event = new Event('change', {
bubbles: true,
cancelable: true,
});
input.dispatchEvent(change_event);
});
input.dispatchEvent(change_event);
});
}
let form_CIPF = document.querySelector('form.fb_form.multistep');
// create an observer on form to check if child nodes are modified
const observer_form_CIPF = new MutationObserver(wait_for_calculation_class_CIPF);
observer_form_CIPF.observe(form_CIPF, {
subtree: true,
attributes: true,
});
// observe mutations to see if they include the addition of class .calculate_field
// if the class is added, call the function that might trigger the change event on it
function wait_for_calculation_class_CIPF(mutationsList) {
mutationsList.forEach((mutation) => {
// check if class where added
if (mutation.type !== 'attributes')
return;
if (mutation.attributeName !== 'class')
return;
// check if added class is .calculate_field
let target = mutation.target;
if (target.classList.contains('calculate_field')) {
// If the class is added, trigger the 'change' event
trigger_change_CIPF(target);
}
}
// create an observer on form to check if child nodes are modified
const observer_form = new MutationObserver(wait_for_calculation_class);
observer_form.observe(form_calculation, {
subtree: true,
attributes: true,
});
// observe mutations to see if they include the addition of class .calculate_field
// if the class is added, call the function that might trigger the change event on it
function wait_for_calculation_class(mutationsList) {
mutationsList.forEach((mutation) => {
// check if class where added
if (mutation.type !== 'attributes')
return;
if (mutation.attributeName !== 'class')
return;
// check if added class is .calculate_field
let target = mutation.target;
if (target.classList.contains('calculate_field')) {
// If the class is added, trigger the 'change' event
trigger_change(target);
}
});
}
}
patch_form_calculation_CIPF();