Apresentar uma reclamação

Formulário de reclamação do cliente

Descreva a sua reclamação e faremos o possível para o ajudar o mais rapidamente possível.

Dados pessoais

Dados de contacto

Dados da transação

jQuery(document).ready(function($) { // Envuelto en jQuery(document).ready para asegurar que jQuery esté listo const JSON_URL = '/data/ubicaciones.json'; // --- 1. LÓGICA DE TRADUCCIÓN --- function getWpmlLanguageCode() { const htmlLang = document.documentElement.lang; if (htmlLang && htmlLang.length >= 2) { return htmlLang.substring(0, 2).toLowerCase(); } return 'es'; } const WEB_LOCALE = getWpmlLanguageCode(); const PLACEHOLDER_TRANSLATIONS = { es: { pais: "Selecciona un país", provincia: "Selecciona una provincia", ciudad: "Selecciona una ciudad", required_msg: "El campo es obligatorio." }, en: { pais: "Select a country", provincia: "Select a state/province", ciudad: "Select a city", required_msg: "This field is required." }, fr: { pais: "Sélectionnez un pays", provincia: "Sélectionnez une province", ciudad: "Sélectionnez une ville", required_msg: "Ce champ est obligatoire." }, it: { pais: "Seleziona un paese", provincia: "Seleziona una provincia", ciudad: "Seleziona una città", required_msg: "Questo campo è obbligatorio." }, pt: { pais: "Selecione um país", provincia: "Selecione um estado/província", ciudad: "Selecione uma cidade", required_msg: "O campo é obrigatório." }, de: { pais: "Wählen Sie ein Land", provincia: "Wählen Sie eine Provinz", ciudad: "Wählen Sie eine Stadt", required_msg: "Dieses Feld ist erforderlich." }, nl: { pais: "Selecteer een land", provincia: "Selecteer een provincie", ciudad: "Selecteer een stad", required_msg: "Dit veld is verplicht." } }; const T = PLACEHOLDER_TRANSLATIONS[WEB_LOCALE] || PLACEHOLDER_TRANSLATIONS['es']; // --- 2. Funciones de Ayuda y Validación --- // Función para resetear select (con corrección de validación) function resetSelect(select, placeholder, disabled = true) { select.innerHTML = ''; const option = document.createElement('option'); option.value = ''; option.textContent = placeholder; option.disabled = true; option.selected = true; select.appendChild(option); select.disabled = disabled; const wrapper = select.closest('.elementor-select-wrapper'); if (wrapper) { wrapper.style.backgroundColor = disabled ? "#f3f3f3" : "#ffffff"; } select.dispatchEvent(new Event('change', { bubbles: true })); select.dispatchEvent(new Event('blur', { bubbles: true })); } // 🛑 FUNCIÓN CRÍTICA: VALIDACIÓN MANUAL DE FALLBACK function manualFormValidation(form) { let isValid = true; // 1. Limpieza de errores y estilos form.find('.custom-error-message').remove(); form.find('.elementor-field').removeClass('input-error'); // 2. Iterar sobre todos los campos requeridos form.find('[required="required"]').each(function() { const field = $(this); const value = field.val() || ''; // Lógica de comprobación: si está vacío const isRadioOrCheckbox = field.is(':radio') || field.is(':checkbox'); const isUncheckedRadio = field.is(':radio') && form.find(`input[name="${field.attr('name')}"]:checked`).length === 0; if (value === '' || isUncheckedRadio) { // 3. Aplicar estilos de error if (!isRadioOrCheckbox) { field.addClass('input-error'); } // 4. Inyectar el mensaje de error const group = field.closest('.elementor-field-group'); const labelText = group.find('.elementor-field-label').text().replace('*', '').trim(); // Si el campo es un radio/checkbox, el labelText será vacío, usamos un texto genérico. const errorMessageText = labelText ? T.required_msg.replace('El campo', `El campo "${labelText}"`) : T.required_msg; const errorMessage = $(`
${errorMessageText}
`); // Asegurar que el mensaje se inyecte una sola vez por grupo if (group.find('.custom-error-message').length === 0) { if (field.parent('.elementor-select-wrapper').length) { group.append(errorMessage); } else if (isRadioOrCheckbox) { group.find('.elementor-field-subgroup').after(errorMessage); } else { field.after(errorMessage); } } isValid = false; } }); // 5. Scroll al primer error if (!isValid) { const firstError = form.find('.input-error, .custom-error-message').first().closest('.elementor-field-group'); if (firstError.length) { $('html, body').animate({ scrollTop: firstError.offset().top - 80 }, 500); } } return isValid; } // --- 3. Lógica de Carga y Llenado de Formularios --- function populateFormSelects(data) { const selectPais = document.getElementById('form-field-pais'); const selectProvincia = document.getElementById('form-field-provincia'); const selectCiudad = document.getElementById('form-field-ciudad'); if (selectPais && selectProvincia && selectCiudad) { resetSelect(selectPais, T.pais, false); resetSelect(selectProvincia, T.provincia); resetSelect(selectCiudad, T.ciudad); data.forEach(pais => { const option = document.createElement('option'); option.value = pais.name; option.textContent = pais.name; selectPais.appendChild(option); }); selectPais.addEventListener('change', () => { const paisSeleccionado = data.find(p => p.name === selectPais.value); resetSelect(selectProvincia, T.provincia, false); resetSelect(selectCiudad, T.ciudad); if (paisSeleccionado && paisSeleccionado.states) { paisSeleccionado.states.forEach(prov => { const option = document.createElement('option'); option.value = prov.name; option.textContent = prov.name; selectProvincia.appendChild(option); }); } }); selectProvincia.addEventListener('change', () => { const paisSeleccionado = data.find(p => p.name === selectPais.value); const provinciaSeleccionada = paisSeleccionado?.states?.find(s => s.name === selectProvincia.value); resetSelect(selectCiudad, T.ciudad, false); if (provinciaSeleccionada && provinciaSeleccionada.cities) { provinciaSeleccionada.cities.forEach(ciudad => { const option = document.createElement('option'); const nombreCiudad = (typeof ciudad === 'string') ? ciudad : ciudad.name; option.value = nombreCiudad; option.textContent = nombreCiudad; selectCiudad.appendChild(option); }); } }); } const selectPaisNacimiento = document.getElementById('form-field-nacimiento'); if (selectPaisNacimiento) { resetSelect(selectPaisNacimiento, T.pais, false); data.forEach(pais => { const option = document.createElement('option'); option.value = pais.name; option.textContent = pais.name; selectPaisNacimiento.appendChild(option); }); } } function displayFatalError() { const form = document.querySelector('.elementor-form'); if (form) { form.innerHTML = `

No se pudieron cargar los datos de ubicación. Por favor, intente de nuevo más tarde.

`; } } // --- 4. Intercepción y Ejecución --- const formElement = $('.elementor-form'); // 🛑 4a. Interceptar el envío del formulario para la validación manual formElement.on('submit', function(e) { e.preventDefault(); // Detener el envío nativo const form = $(this); if (manualFormValidation(form)) { // Si es válido, disparamos la función de envío AJAX de Elementor if (form.data('submit-handler')) { form.data('submit-handler')(e); } else { // Si no hay manejador AJAX, forzamos el envío HTML nativo form[0].submit(); } } }); // 🛑 4b. Carga de Datos (con setTimeout para el timing) setTimeout(function() { fetch(JSON_URL) .then(response => { if (!response.ok) { throw new Error(`Error al cargar JSON: ${response.status} ${response.statusText}`); } return response.json(); }) .then(data => { populateFormSelects(data); // Reiniciar el formulario después de llenar para asegurar que Elementor está listo if (typeof jQuery !== 'undefined') { formElement.trigger('reset'); } }) .catch(error => { displayFatalError(); }); }, 50); });