201} else {202tcalc__initFormContainer(rec);203}204205function tcalc__initFormContainer(formContainer) {206const wrappers = rec.querySelectorAll('[data-input-lid="' + idField + '"]');207const hasConditionalForm =208formContainer.classList.contains('t-conditional-form') ||209Boolean(formContainer.querySelector('.t-conditional-form'));210211if (hasConditionalForm) {212const CONDITIONAL_FORM_INIT_EVENT = 'conditional-form-init';
const CONDITIONAL_FORM_READY_ATTR = 'data-conditional-form-ready'; if (formContainer.getAttribute(CONDITIONAL_FORM_READY_ATTR) === 'true') { for (let i = 0; i < wrappers.length; i++) { tcalc__initWrapper(wrappers[i], rec); } } else { formContainer.addEventListener( CONDITIONAL_FORM_INIT_EVENT, function () { for (let i = 0; i < wrappers.length; i++) { tcalc__initWrapper(wrappers[i], rec); } }, { once: true } ); } } else { for (let i = 0; i < wrappers.length; i++) { tcalc__initWrapper(wrappers[i], rec); } } }}/** * Get parse expression formula * * @param {string} strExpr - string formula * @returns {Expression} - obj containing data about the formula */function tcalc__getParseExpression(strExpr) { var chars = strExpr.split(''); var arrOperands = []; var arrOperators = []; var index = 0; var isOperatorsLast = true; arrOperands[index] = Object.create(null); arrOperands[index].str = ''; // tcalc__parse the expression for (var i = 0; i < chars.length; i++) { if (chars[i] === '(' || chars[i] === ')') continue; if ((chars[i] === '+' || chars[i] === '-' || chars[i] === '*' || chars[i] === '/') && !isOperatorsLast) { arrOperators[index] = chars[i]; index++; arrOperands[index] = Object.create(null); arrOperands[index].str = ''; isOperatorsLast = true; } else { arrOperands[index].str += chars[i]; isOperatorsLast = false; } } return { str: strExpr, operands: arrOperands, operators: arrOperators };}/** * Add obj data about type operand, value operand and find the appropriate input * * @param {HTMLElement} rec - wrap block for search elements * @param {Expression} objExpr - object data */function tcalc__cashOperandsFieldsEls(rec, objExpr) { for (var i = 0; i < objExpr.operands.length; i++) { var str = objExpr.operands[i].str; // if operand is a number if (!isNaN(str)) { objExpr.operands[i].type = 'number'; objExpr.operands[i].value = +objExpr.operands[i].str; continue; } // if operand is a variable, connected with field var fields = rec.querySelectorAll('[name="' + str + '"]'); var hasConditionalField = Array.from(fields).some(function (field) { return Boolean(field.closest('.t-input-group[data-conditionals], .t-conditional')); }); if (fields) { objExpr.operands[i].type = 'variable'; objExpr.operands[i].field = fields; objExpr.operands[i].hasConditionalField = hasConditionalField; } else {