jsOMS/Model/Action/Dom/GetValue.js
Dennis Eichhorn 7b75ec58f7
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
CI / general_module_workflow_js (push) Has been cancelled
fix permissions
2025-04-02 14:15:07 +00:00

44 lines
1.3 KiB
JavaScript

import { GeneralUI } from '../../../UI/GeneralUI.js';
/**
* Get value from dom.
*
* @param {Object} action Action data
* @param {function} callback Callback
* @param {string} id Action element
*
* @since 1.0.0
*/
export function domGetValue (action, callback, id)
{
'use strict';
const e = action.base === 'self'
? (action.selector === '' || typeof action.selector === 'undefined'
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
let value = {};
for (const i in e) {
/** global: HTMLElement */
if (!Object.prototype.hasOwnProperty.call(e, i) || !(e[i] instanceof HTMLElement)) {
continue;
}
const eId = (typeof e[i].getAttribute('name') !== 'undefined' && e[i].getAttribute('name') !== '' && e[i].getAttribute('name') !== null)
? e[i].getAttribute('name')
: e[i].getAttribute('id');
if (e[i].tagName.toLowerCase() === 'form') {
value = window.omsApp.uiManager.getFormManager().get(eId).getData();
break;
} else {
value[eId] = GeneralUI.getValueFromDataSource(e[i]);
}
}
callback(value);
};