* @returns {HTMLDivElement}
1715function t_zeroForms__createContactMethodRadio(contactMethod, options) { 1716 const { inputId, inputName, isRequired, isChecked } = options; 1718 const wrapper = t_zeroForms__createWrapper(['t-radio__item', 't-contact-method__type', 't-text', 't-text_xs']); 1719 wrapper.setAttribute('data-method-type', contactMethod.type); 1721 const label = document.createElement('label'); 1722 label.classList.add('t-contact-method__type-label'); 1723 label.htmlFor = inputId; 1724 label.insertAdjacentHTML('beforeend', t_zeroForms__getContactMethodIcon(contactMethod.type)); 1726 const title = document.createElement('span'); 1727 title.classList.add('t-contact-method__title'); 1728 title.setAttribute('data-contact-method', contactMethod.type); 1729 title.textContent = contactMethod.title; 1730 label.appendChild(title); 1732 const input = document.createElement('input'); 1734 input.type = 'radio'; 1735 input.classList.add('t-radio', 'js-tilda-rule', 't-contact-method__type-input'); 1736 input.name = inputName; 1737 input.value = contactMethod.type; 1739 input.setAttribute('data-tilda-req', '1'); 1740 input.setAttribute('aria-required', 'true'); 1742 // атрибут, а не свойство checked: от него зависит состояние после сброса формы 1743 if (isChecked) input.setAttribute('checked', ''); 1745 wrapper.appendChild(label); 1746 wrapper.appendChild(input); 1752 * Создает группу полей для ввода значения способа связи (телефон и/или текстовое поле) 1754 * @param {string} recid 1756 * elementObj: FormObjectEl, 1757 * contactMethod: ContactMethod, 1758 * inputName: string, 1759 * inputStyles: Object, 1760 * inputPreferences: Object, 1761 * isDefault: boolean, 1763 * @returns {HTMLDivElement} 1765function t_zeroForms__createContactMethodValueGroup(recid, options) { 1766 const { elementObj, contactMethod, inputName, inputStyles, inputPreferences, isDefault } = options; 1767 const { type, hasPhone, hasText } = contactMethod; 1768 // При выборе способа связи показывается текстовое поле, если оно есть. 1769 // Повторяет t_contactMethod__getDefaultInputTypeForContactMethod 1770 const defaultInputType = hasText ? 'text' : 'phone'; 1772 // Сразу рендерим состояние, в котором поле будет после инициализации tilda-contact-method: 1773 // видно только поле способа связи по умолчанию, остальные скрыты и отключены. Иначе до инициализации 1774 // в форме видны поля всех способов связи, и форма "прыгает". 1775 const group = document.createElement('div'); 1776 group.classList.add(`t-contact-method__${type}-value`); 1777 if (hasPhone) group.classList.add('t-phonemask-input-group'); 1778 if (hasPhone && hasText) group.classList.add('t-contact-method__hybrid'); 1779 if (!isDefault) group.classList.add('t-contact-method__hidden'); 1781 const createInputBlock = (input, inputType) => { 1782 const isActive = isDefault && inputType === defaultInputType; 1784 input.name = inputName; 1785 input.classList.add('t-input'); 1786 if (inputPreferences.secondaryClassName) input.classList.add(inputPreferences.secondaryClassName); 1787 if (inputPreferences.require) { 1788 input.setAttribute('data-tilda-req', '1'); 1789 input.setAttribute('aria-required', 'true'); 1791 // Неактивные поля отключаем так же, как t_contactMethod__disable: они не валидируются и не отправляются 1793 input.classList.add('js-tilda-rule'); 1794 // label заголовка поля ссылается на input_<lid>, привязываем его к полю, которое видно по умолчанию 1795 input.id = 'input_' + elementObj.lid; 1797 input.disabled = true; 1799 t_zeroForms__appendStylesToField(input, inputStyles);