601const errors = window.tildaForm.validate(currentElement);602if (!errors || errors.length === 0) return false;603604const stepErrors = filterStepRelatedErrors(errors);605const hasStepErrors = !!stepErrors.length;606607// Нужно показать ошибки руками, тк они показываются скриптом формы только при нажатии на submit.608if (hasStepErrors) {609window.tildaForm.showErrors(currentElement, stepErrors, { inputBoxSelector: '.t-input-group' });610requestAnimationFrame(() => {611t_quiz__adjustStepToHeight({ rec }, true);
}); } return hasStepErrors; } /** * Возвращает ошибки, которые относятся тллько к текущему шагу. * Ошибка emptyfill актуальна только при отправке формы. * @param {Array<object>} stepErrors */ function filterStepRelatedErrors(stepErrors) { return stepErrors.filter(error => error.type.some(errorType => errorType !== 'emptyfill')); } function setSpecImageRatio() { const specImage = rec.querySelector( '.t-step-form__step_active .t-quiz__cover__side-cover .t-quiz__cover__img, .t-step-form__step_active .t-quiz__result-img-wrapper' ); if (!specImage) return; const specImageUrl = window.getComputedStyle(specImage).getPropertyValue('background-image').slice(5, -2); // Создаем временный элемент изображения для определения размеров const img = document.createElement('img'); img.src = specImageUrl; img.onload = function () { const imageWidth = img.width; const imageHeight = img.height; const imageRatio = (imageWidth / imageHeight).toFixed(1); const specImageRatio = Math.max(imageRatio, 1); changeSpecImageRatio(specImage, specImageRatio); function handleSpecImageRatioResize() { t_quiz__getDebouncedFunc(changeSpecImageRatio, `${recid}_spec-ratio`)(specImage, specImageRatio); } window.addEventListener('resize', handleSpecImageRatioResize); }; } function changeSpecImageRatio(specImage, ratio) { let aspectRatio = ratio; if (t_quiz__isMobile()) { aspectRatio = ratio; } else if (specImage.classList.contains('t-quiz__cover__img')) { aspectRatio = 'unset'; } else if (specImage.classList.contains('t-quiz__result-img-wrapper')) { aspectRatio = '16/9'; } specImage.style.aspectRatio = aspectRatio; } /** * @returns {QuizAnalytics | undefined} */ function initAnalytics() { try { const analytics = t_quiz__analytics({ rec }); if (!analytics) return; if ('IntersectionObserver' in window) { const stepObserver = new IntersectionObserver(function (entries, observer) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; const target = entry.target; const currentStep = StepsManager.getCurrentStepInfo(); if (currentStep.step && target !== currentStep.step.element) return; const stepIndex = currentStep.step.element.getAttribute('data-step-index') || currentStep.index; const stepOrder = Number(stepIndex) + 1; analytics.viewStep(stepOrder); observer.unobserve(target); }); }); preparedSteps.forEach(step => { stepObserver.observe(step.element); }); } } catch (e) { console.warn(e); } } function restartAnalytics() { const analytics = t_quiz__analytics({ rec }); if (!analytics) return; // Очищаем все просмотренные шаги analytics.restart();