* @param {FormVariable} variable
3515function t_forms__updateSystemVariable(rec, elem, variable) { 3516 const SYS_VARS = t_forms__getSystemVariables(); 3517 const form = rec.querySelector('.t-form'); 3520 let value = variable.name; 3522 if (variable.name === SYS_VARS.LEAD_ID) { 3523 const { tildaTranId } = form; 3524 // eg: 12098159:7157790111 3525 const [, leadId] = (tildaTranId || '').split(':'); 3527 value = leadId || '0'; 3530 t_forms__updateVariables(elem, variable, value); 3534 * Обновляет все системные переменные в блоке. 3535 * @param {Element} elem 3537function t_forms__updateAllSystemVariables(elem) { 3538 const rec = elem.closest('.t-rec'); 3539 const variables = t_forms__getUsedVariables([rec], { unique: true }); 3540 const systemVars = variables.filter(t_forms__isSystemVariable); 3542 systemVars.forEach(variable => { 3543 t_forms__updateSystemVariable(rec, rec, variable); 3548 * Обновляет все переменные в блоке. 3549 * @param {Element} elem 3551async function t_forms__updateAllVariables(elem) { 3553 const rec = elem.closest('.t-rec'); 3554 const variables = t_forms__getUsedVariables([rec], { unique: true }); 3556 const systemVars = variables.filter(t_forms__isSystemVariable); 3557 systemVars.forEach(variable => t_forms__updateSystemVariable(rec, rec, variable)); 3559 const inputVars = variables.filter(variable => !t_forms__isSystemVariable(variable)); 3561 const promises = inputVars.map(async variable => { 3562 const inputGroup = t_forms__findFormField(rec, variable.name); 3563 if (!inputGroup) return Promise.resolve(); 3565 const fieldApi = await formsApi.t_formsApi__initTildaField(inputGroup); 3566 if (!fieldApi) return Promise.resolve(); 3568 t_forms__updateInputVariable(rec, variable, fieldApi); 3569 return Promise.resolve(); 3572 await Promise.all(promises); 3574 console.error('Failed to update variabls in rec:', e); 3579 * @typedef {Object} FormVariable 3580 * @prop {string} name 3581 * @prop {string} domain 3584 * @param {Element[]} elems 3585 * @param {{ unique?: boolean }} options 3586 * @returns {FormVariable[]} 3588function t_forms__getUsedVariables(elems, options = {}) { 3589 const { unique } = options; 3591 // Собираем все переменные из элементов 3592 const variables = Array.from(elems).flatMap( 3594 Array.from(elem.querySelectorAll('.t-variable-placeholder')) 3595 .map(placeholder => { 3597 name: placeholder.getAttribute('data-variable'), 3598 domain: placeholder.getAttribute('data-variable-domain'),