fix form bugs and add actions for click and submit

This commit is contained in:
Dennis Eichhorn 2020-04-18 22:37:05 +02:00
parent 43c763d405
commit 6f08f7f81a
3 changed files with 53 additions and 1 deletions

25
Model/Action/Dom/Click.js Normal file
View File

@ -0,0 +1,25 @@
/**
* Click dom element.
*
* @param {Object} action Action data
* @param {function} callback Callback
* @param {string} id Action element
*
* @since 1.0.0
*/
export function domClickAction (action, callback, id)
{
"use strict";
const click = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
if (!click) {
return;
}
for (const i of click) {
i.click();
}
callback();
};

View File

@ -0,0 +1,27 @@
/**
* Click dom element.
*
* @param {Object} action Action data
* @param {function} callback Callback
* @param {string} id Action element
*
* @since 1.0.0
*/
export function formSubmitAction (action, callback, id)
{
"use strict";
const submit = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
if (!submit) {
return;
}
const formManager = window.omsApp.uiManager.getFormManager();
for (const i of submit) {
formManager.submit(formManager.get(i.id));
}
callback();
};

View File

@ -430,7 +430,7 @@ export class FormView
for (const key in data) {
if (data.hasOwnProperty(key)) {
formData.append(key, data[key].constructor === Array ? JSON.stringify(data[key]) : data[key]);
formData.append(key, data[key] !== null && data[key].constructor === Array ? JSON.stringify(data[key]) : data[key]);
}
}