@nent/core
Version:
32 lines (29 loc) • 1.01 kB
JavaScript
/*!
* NENT 2022
*/
;
/**
* It checks if the input elements are valid or not.
* @param {HTMLElement} rootElement - HTMLElement - The root element to search for inputs.
* @returns A boolean value.
*/
function getChildInputValidity(rootElement) {
const inputElements = [
...Array.from(rootElement.querySelectorAll('input')),
...Array.from(rootElement.querySelectorAll('textarea')),
...Array.from(rootElement.querySelectorAll('select')),
...Array.from(rootElement.querySelectorAll('*[n-validate]')),
];
const results = inputElements.map((i) => {
var _a, _b;
if (((_a = i.checkValidity) === null || _a === void 0 ? void 0 : _a.call(i)) === false ||
((_b = i.reportValidity) === null || _b === void 0 ? void 0 : _b.call(i)) === false) {
return false;
}
return true;
});
if (rootElement.querySelectorAll('*[invalid]').length)
return false;
return !results.some(v => v == false);
}
exports.getChildInputValidity = getChildInputValidity;