jQuery(window).on('elementor/frontend/init', function() {
elementorFrontend.hooks.addAction('frontend/element_ready/form.default', function(scope) {
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" },
en: { pais: "Select a country" },
fr: { pais: "Sélectionnez un pays" },
it: { pais: "Seleziona un paese" },
pt: { pais: "Selecione um país" },
de: { pais: "Wählen Sie ein Land" },
nl: { pais: "Selecteer een land" }
};
const T_PAIS = PLACEHOLDER_TRANSLATIONS[WEB_LOCALE]?.pais || PLACEHOLDER_TRANSLATIONS.es.pais;
const JSON_URL = '/data/ubicaciones.json';
setTimeout(function() {
fetch(JSON_URL)
.then(response => {
if (!response.ok) throw new Error(`Error al cargar JSON: ${response.statusText}`);
return response.json();
})
.then(data => {
const selectPaisOrigen = scope[0].querySelector('#form-field-pais_origen');
const formElement = scope[0].querySelector('.elementor-form');
if (!selectPaisOrigen) return;
const wrapper = selectPaisOrigen.closest('.elementor-select-wrapper');
selectPaisOrigen.innerHTML = '';
const defaultOption = document.createElement('option');
defaultOption.value = '';
defaultOption.textContent = T_PAIS;
defaultOption.disabled = true;
defaultOption.selected = true;
selectPaisOrigen.appendChild(defaultOption);
selectPaisOrigen.dispatchEvent(new Event('change', { bubbles: true }));
selectPaisOrigen.dispatchEvent(new Event('blur', { bubbles: true }));
if (wrapper) wrapper.style.backgroundColor = "#FFFFFF";
data.forEach(pais => {
const option = document.createElement('option');
option.value = pais.name;
option.textContent = pais.name;
selectPaisOrigen.appendChild(option);
});
if (formElement && typeof jQuery !== 'undefined') {
jQuery(formElement).trigger('reset');
jQuery(formElement).trigger('input');
}
})
.catch(error => {
const formContainer = scope[0].querySelector('.elementor-widget-form');
if (formContainer) {
formContainer.innerHTML = `
Error al cargar los datos de ubicación.
`; } }); }, 50); }); });