DATA FORM
bergamo - attrazioni locali
Posti di interesse
Le diverse attrazioni a portata di mano. Che si tratti di monumenti storici intrisi di storie, meraviglie naturali mozzafiato in attesa di esplorazione, o vivaci centri culturali pulsanti di vita, ogni luogo promette un’avventura unica. Da parchi sereni perfetti per la contemplazione tranquilla a mercati vivaci con colore ed energia, c’ĆØ qualcosa per catturare l’immaginazione di ogni viaggiatore. Lasciatevi andare e scoprite il fascino e il carattere intessuti in ogni angolo di questa destinazione accattivante.
document.addEventListener('DOMContentLoaded', function () { const globalOptionsSelect = document.getElementById('globalOptions'); const globalOptions = Array.from(globalOptionsSelect.options); // Get global options in array format
// Helper function to populate the options list based on search input function filterGlobalOptions(query) { return globalOptions.filter(option => option.text.toLowerCase().includes(query.toLowerCase())); }
// Function to dynamically handle search and option selection function handleSearchInput(searchInput) { const optionsList = searchInput.nextElementSibling; // Get the options list div const selectId = searchInput.getAttribute('data-select-id'); const correspondingSelect = document.getElementById(selectId); // Get the corresponding select element
// Sync required and disabled attributes syncAttributes(correspondingSelect, searchInput);
// Observe attribute changes on the
// When the user types into the search bar searchInput.addEventListener('input', function () { const query = searchInput.value; const matchingOptions = filterGlobalOptions(query);
// Clear and populate options list optionsList.innerHTML = ''; if (matchingOptions.length > 0) { matchingOptions.forEach(option => { const optionDiv = document.createElement('div'); optionDiv.classList.add('option-item'); optionDiv.textContent = option.text; optionDiv.setAttribute('data-value', option.value); optionsList.appendChild(optionDiv); }); optionsList.style.display = 'block'; // Show the dropdown } else { optionsList.style.display = 'none'; // Hide if no matches } });
// Handle selecting an option from the dropdown optionsList.addEventListener('click', function (e) { if (e.target.classList.contains('option-item')) { const selectedValue = e.target.getAttribute('data-value'); const selectedLabel = e.target.textContent;
// Add the selected option to the corresponding
// Trigger change event on
// Update the search input to show the selected option searchInput.value = selectedLabel; optionsList.style.display = 'none'; // Hide options list } }); }
// Sync the attributes between
// Sync 'disabled' attribute if (selectElement.disabled) { searchInput.setAttribute('disabled', 'disabled'); // Clear the select and search input when disabled clearSelectOptions(selectElement, searchInput); } else { searchInput.removeAttribute('disabled'); } }
// Function to clear the selected option from the
// Programmatically clear the selection in the
// Clear the search input as well searchInput.value = '';
// Trigger change event to ensure hidden fields and other listeners detect this update const event = new Event('change', { bubbles: true }); selectElement.dispatchEvent(event); }
// Observe changes in the
observer.observe(selectElement, { attributes: true }); }
// Function to initialize search functionality for all matching elements function initializeSearchInputs() { document.querySelectorAll('.custom-search').forEach(searchInput => { // Ensure that the input has not already been initialized if (!searchInput.getAttribute('data-initialized')) { handleSearchInput(searchInput); searchInput.setAttribute('data-initialized', 'true'); // Mark as initialized } }); }
// Initial setup for elements loaded with the page initializeSearchInputs();
// Set up MutationObserver to detect dynamically added .custom-search elements const observer = new MutationObserver(function (mutationsList) { mutationsList.forEach(mutation => { if (mutation.type === 'childList') { mutation.addedNodes.forEach(node => { if (node.nodeType === 1 && node.classList.contains('custom-search')) { handleSearchInput(node); // Initialize the newly added search input node.setAttribute('data-initialized', 'true'); } }); } });
// Re-initialize in case any new search inputs were added in bulk initializeSearchInputs(); });
// Observe the entire document for additions of elements observer.observe(document.body, { childList: true, subtree: true // Observe the entire subtree to detect dynamically added elements }); });
document.addEventListener('DOMContentLoaded', function () { // Helper function to update hidden field based on select element function updateHiddenField(selectElementId_hidden, hiddenFieldId_hidden) { const selectElement_hidden = document.getElementById(selectElementId_hidden); const hiddenField_hidden = document.getElementById(hiddenFieldId_hidden);
// Check if both elements exist if (!selectElement_hidden || !hiddenField_hidden) { return; }
// Function to update the hidden field value function updateHiddenFieldValue() { const selectedOption_hidden = selectElement_hidden.options[selectElement_hidden.selectedIndex]; hiddenField_hidden.value = selectedOption_hidden && selectedOption_hidden.value ? selectedOption_hidden.text : ''; }
// Update hidden field when the select element value changes (on user interaction) selectElement_hidden.addEventListener('change', function () { updateHiddenFieldValue(); // Update hidden field on change });
// Initialize hidden field value on page load updateHiddenFieldValue(); }
// Helper function to clear the
if (!selectElement_hidden || !hiddenField_hidden) { return; }
// Clear the
// Clear the hidden field hiddenField_hidden.value = '';
// Trigger the change event to ensure all event listeners fire const event = new Event('change', { bubbles: true }); selectElement_hidden.dispatchEvent(event); }
// Set up event listeners for each select element and corresponding hidden field function initializeHiddenFieldListeners() { updateHiddenField('cittadinanza', 'cittadinanza_name'); updateHiddenField('stato_nascita', 'stato_nascita_name'); updateHiddenField('comune_nascita', 'comune_nascita_name'); updateHiddenField('COMUNE_RESIDENZA', 'COMUNE_RESIDENZA_name'); updateHiddenField('STATO_rilascio', 'STATO_rilascio_name'); updateHiddenField('stato_RESIDENZA', 'stato_RESIDENZA_name'); updateHiddenField('comune_rilascio', 'comune_rilascio_name'); updateHiddenField('billing_NATIONALITY', 'billing_NATIONALITY_name'); }
// Set up MutationObserver to detect changes in disabled state and dynamically added elements const observer = new MutationObserver(function (mutationsList) { mutationsList.forEach(mutation => { if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') { const selectElement = mutation.target; const selectId = selectElement.id; const hiddenFieldId = selectId + '_name'; // Assuming hidden field IDs are based on select IDs
if (selectElement.disabled) {
clearSelectAndHiddenField(selectId, hiddenFieldId); // Clear the
// Observe all the select elements for attribute changes (like 'disabled') document.querySelectorAll('select').forEach(selectElement => { observer.observe(selectElement, { attributes: true }); });
// Initialize listeners on page load initializeHiddenFieldListeners(); });
document.addEventListener('DOMContentLoaded', function() { var selectElementcomune_nascita = document.getElementById('comune_nascita'); var hiddenFieldcomune_nascita = document.getElementById('province_nascita');
if (selectElementcomune_nascita) { selectElementcomune_nascita.addEventListener('change', function() { // Get the selected option text var selectedOptionTextcomune_nascita = this.options[this.selectedIndex].text;
// Extract the province code var provinceCodecomune_nascita = selectedOptionTextcomune_nascita.split(', ')[1];
// Set the hidden field value hiddenFieldcomune_nascita.value = provinceCodecomune_nascita; }); }
var selectElementCOMUNE_RESIDENZA = document.getElementById('COMUNE_RESIDENZA'); var hiddenFieldCOMUNE_RESIDENZA = document.getElementById('province_residenza');
if (selectElementCOMUNE_RESIDENZA) { selectElementCOMUNE_RESIDENZA.addEventListener('change', function() { // Get the selected option text var selectedOptionTextCOMUNE_RESIDENZA = this.options[this.selectedIndex].text;
// Extract the province code var provinceCodeCOMUNE_RESIDENZA = selectedOptionTextCOMUNE_RESIDENZA.split(', ')[1];
// Set the hidden field value hiddenFieldCOMUNE_RESIDENZA.value = provinceCodeCOMUNE_RESIDENZA; }); } });
function updateRAGIONE_SOCIALEField() { const selectElement = document.getElementById('AZIENDA'); const inputElement = document.getElementById('billing_RAGIONE_SOCIALE'); if (selectElement.value === 'PERSONA FISICA') { inputElement.disabled = true; inputElement.value = ''; // Clear the input field when it's disabled } else { inputElement.disabled = false; } }
// Add event listener to the select element document.getElementById('AZIENDA').addEventListener('change', updateRAGIONE_SOCIALEField);
// Initial check on page load updateRAGIONE_SOCIALEField();
document.addEventListener('DOMContentLoaded', function () { const selectElement_block = document.getElementById('tipo_alloggiato'); const addButton = document.getElementById('addMemberBtn'); const notice = document.getElementById('notice');
function checkSelectValue() { if (selectElement_block.value === '16' || selectElement_block.value === '') { addButton.disabled = true; notice.style.display = 'block'; } else { addButton.disabled = false; notice.style.display = 'none'; } }
selectElement_block.addEventListener('change', checkSelectValue);
// Initial check in case no option is selected on page load checkSelectValue(); });
document.addEventListener('DOMContentLoaded', function() { const fileInput = document.querySelector('#upload_document'); const fileList = document.querySelector('#fileList'); const errorMessage = document.querySelector('#error-message'); const form = document.querySelector('#custom_form'); // Assuming your form has an ID 'custom_form'
form.addEventListener('submit', function(event) { event.preventDefault(); // Prevent the default form submission
const files = fileInput.files; const formData = new FormData();
for (let i = 0; i < files.length; i++) { formData.append('upload_document[]', files[i]); } formData.append('action', 'handle_file_upload'); formData.append('security', '95d10165c3'); fetch('https://dolcevitabnbitaly.com/wp-admin/admin-ajax.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { data.data.files.forEach(file => { const li = document.createElement('li'); li.textContent = file.url; fileList.appendChild(li); });
// Remove the event listener to prevent infinite loop form.removeEventListener('submit', arguments.callee);
// Create a hidden input to mark form submission const hiddenSubmitInput = document.createElement('input'); hiddenSubmitInput.type = 'hidden'; hiddenSubmitInput.name = 'submit_custom_form'; hiddenSubmitInput.value = '1'; form.appendChild(hiddenSubmitInput);
// Resubmit the form normally form.submit(); } else { errorMessage.textContent = data.data; } }) .catch(error => { console.error('Error:', error); errorMessage.textContent = 'An error occurred during the upload.'; }); }); });
// Get the select element by its ID // Updated function to handle dynamically added member fields const newSelectElements = document.querySelectorAll('#comune_nascita'); const newStateElement = document.querySelector('#stato_nascita');
// Unique function for the new elements const updateRequiredAttributeForNewElements = () => { if (newStateElement.value !== '100000100') { newSelectElements.forEach(element => { element.removeAttribute('required'); element.setAttribute('disabled', true); }); } else { newSelectElements.forEach(element => { element.setAttribute('required', true); element.removeAttribute('disabled'); }); } };
// Initial call to set the correct required attribute state updateRequiredAttributeForNewElements();
// Event listener for the new state element newStateElement.addEventListener('change', updateRequiredAttributeForNewElements);
const newSelectElementsRESIDENCE = document.querySelectorAll('#comune_rilascio'); const newStateElementRESIDENCE = document.querySelector('#STATO_rilascio');
// Unique function for the new elements const updateRequiredAttributeForNewElementsRESIDENCE = () => { if (newStateElementRESIDENCE.value !== '100000100') { newSelectElementsRESIDENCE.forEach(element => { element.removeAttribute('required'); element.setAttribute('disabled', true); }); } else { newSelectElementsRESIDENCE.forEach(element => { element.setAttribute('required', true); element.removeAttribute('disabled'); }); } };
// Initial call to set the correct required attribute state updateRequiredAttributeForNewElementsRESIDENCE();
// Event listener for the new state element newStateElementRESIDENCE.addEventListener('change', updateRequiredAttributeForNewElementsRESIDENCE);
const newSelectElementsCOMUNE_RESIDENZA = document.querySelectorAll('#COMUNE_RESIDENZA'); const newStateElementCOMUNE_RESIDENZA = document.querySelector('#stato_RESIDENZA');
// Unique function for the new elements const updateRequiredAttributeForNewElementsCOMUNE_RESIDENZA = () => { if (newStateElementCOMUNE_RESIDENZA.value !== '100000100') { newSelectElementsCOMUNE_RESIDENZA.forEach(element => { element.removeAttribute('required'); element.setAttribute('disabled', true); }); } else { newSelectElementsCOMUNE_RESIDENZA.forEach(element => { element.setAttribute('required', true); element.removeAttribute('disabled'); }); } };
// Initial call to set the correct required attribute state updateRequiredAttributeForNewElementsCOMUNE_RESIDENZA();
// Event listener for the new state element newStateElementCOMUNE_RESIDENZA.addEventListener('change', updateRequiredAttributeForNewElementsCOMUNE_RESIDENZA);
/////////new change document.addEventListener("DOMContentLoaded", function() { var aziendaSelect = document.getElementById('AZIENDA'); var nationalitySelect = document.getElementById('billing_NATIONALITY');
var businessNameField = document.getElementById('billing_RAGIONE_SOCIALE'); var vatNumberField = document.getElementById('billing_VAT'); var recipientField = document.getElementById('billing_RECIPIENT'); var pecField = document.getElementById('billing_PEC');
var taxIdField = document.getElementById('billing_TAX'); var postalCodeField = document.getElementById('billing_CAP'); var billing_cognome = document.getElementById('billing_cognome'); var billing_nome = document.getElementById('billing_nome'); var commonFields = [ document.getElementById('billing_NATIONALITY'), document.getElementById('billing_INDIRIZZO'), document.getElementById('billing_COMUNE') ];
function handleFieldVisibility() { var selectedType = aziendaSelect.value; var nationality = nationalitySelect.value; var isItalian = nationality === '100000100'; // Code for Italy
if (selectedType === 'COMPANY / AZIENDA') { enableAndRequireFields([businessNameField, vatNumberField, recipientField, pecField]); disableAndClearFields([taxIdField, billing_cognome, billing_nome]);
if (isItalian) { recipientField.required = true; pecField.required = true; } else { recipientField.required = false; pecField.required = false; disableAndClearFields([recipientField]); recipientField.value = ' '; // Set the value to a space
} } else if (selectedType === 'PERSONA FISICA') { disableAndClearFields([businessNameField, vatNumberField, recipientField, pecField]); enableAndRequireFields([taxIdField, billing_cognome, billing_nome]);
if (isItalian) { enableAndRequireFields([postalCodeField]); enableAndRequireFields([taxIdField]);
} else { disableAndClearFields([postalCodeField]); taxIdField.required = false; } }
// Common fields for both types commonFields.forEach(function(field) { field.disabled = false; field.required = true; }); }
function enableAndRequireFields(fields) { fields.forEach(function(field) { field.disabled = false; field.required = true; }); }
function disableAndClearFields(fields) { fields.forEach(function(field) { field.disabled = true; field.required = false; field.value = ''; }); }
// Event listener for changes in type and nationality aziendaSelect.addEventListener('change', handleFieldVisibility); nationalitySelect.addEventListener('change', handleFieldVisibility);
// Initial call to set fields correctly on page load handleFieldVisibility(); });
document.addEventListener('DOMContentLoaded', function () { function handleHiddenFields(form) { const hiddenFields = form.querySelectorAll('[aria-hidden="true"], [tabindex="-1"], [style*="display:none"] select, [style*="display:none"] input');
hiddenFields.forEach(field => { field.disabled = true; // Disable them to avoid validation field.removeAttribute('required'); // Ensure 'required' attribute is removed }); }
document.querySelectorAll('form').forEach(form => { form.addEventListener('submit', function (event) { handleHiddenFields(form); // Apply before submission }); });
// Remove hidden field constraints immediately on load document.querySelectorAll('form').forEach(handleHiddenFields); });
const fileInput = document.getElementById('upload_document'); const fileList = document.getElementById('fileList'); const errorMessage = document.getElementById('error-message'); const MAX_SIZE_MB = 3; const MAX_SIZE_BYTES = MAX_SIZE_MB * 1024 * 1024;
fileInput.addEventListener('change', function() { fileList.innerHTML = ''; errorMessage.textContent = ''; let valid = true;
for (let i = 0; i < fileInput.files.length; i++) { const file = fileInput.files[i]; const listItem = document.createElement('li'); listItem.textContent = `${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`; if (file.size > MAX_SIZE_BYTES) { listItem.style.color = 'red'; errorMessage.textContent = 'Some files exceed the maximum size of 3 MB.'; valid = false; }
fileList.appendChild(listItem); }
if (!valid) { fileInput.value = ''; // Clear the input if any file is invalid } }); let memberId = 1;
function addMemberSection() { const memberSections = document.getElementById('memberSections');
if (memberId > 9) { alert('You cannot add more than 10 members.'); return; }
const memberDiv = document.createElement('div'); memberDiv.classList.add('member-section'); memberDiv.innerHTML = `
Member ${memberId}
`; const scriptContent = ` function updateHiddenField_${memberId}(selectId, hiddenFieldId) { const selectElement = document.getElementById(selectId); const hiddenField = document.getElementById(hiddenFieldId);
if (selectElement && hiddenField) { selectElement.addEventListener('change', function () { const selectedOption = selectElement.options[selectElement.selectedIndex]; if (selectedOption.value) { hiddenField.value = selectedOption.text; } else { hiddenField.value = ''; } });
// Initialize hidden field value on page load const selectedOption = selectElement.options[selectElement.selectedIndex]; if (selectedOption.value) { hiddenField.value = selectedOption.text; } else { hiddenField.value = ''; } } }
// Set up event listeners for each select element and corresponding hidden field updateHiddenField_${memberId}('cittadinanza_${memberId}', 'cittadinanza_name_${memberId}'); updateHiddenField_${memberId}('stato_nascita_${memberId}', 'stato_nascita_name_${memberId}'); updateHiddenField_${memberId}('comune_nascita_${memberId}', 'comune_nascita_name_${memberId}'); updateHiddenField_${memberId}('COMUNE_RESIDENZA_${memberId}', 'COMUNE_RESIDENZA_name_${memberId}'); updateHiddenField_${memberId}('stato_RESIDENZA_${memberId}', 'stato_RESIDENZA_name_${memberId}');
var selectElementcomune_nascita_${memberId} = document.getElementById('comune_nascita_${memberId}'); var hiddenFieldcomune_nascita_${memberId} = document.getElementById('province_nascita_${memberId}');
if (selectElementcomune_nascita_${memberId}) { selectElementcomune_nascita_${memberId}.addEventListener('change', function() { // Get the selected option text var selectedOptionTextcomune_nascita_${memberId} = this.options[this.selectedIndex].text;
// Extract the province code var provinceCodecomune_nascita_${memberId} = selectedOptionTextcomune_nascita_${memberId}.split(', ')[1];
// Set the hidden field value hiddenFieldcomune_nascita_${memberId}.value = provinceCodecomune_nascita_${memberId}; }); }
var selectElementCOMUNE_RESIDENZA_${memberId} = document.getElementById('COMUNE_RESIDENZA_${memberId}'); var hiddenFieldCOMUNE_RESIDENZA_${memberId} = document.getElementById('province_residenza_${memberId}');
if (selectElementCOMUNE_RESIDENZA_${memberId}) { selectElementCOMUNE_RESIDENZA_${memberId}.addEventListener('change', function() { // Get the selected option text var selectedOptionTextCOMUNE_RESIDENZA_${memberId} = this.options[this.selectedIndex].text;
// Extract the province code var provinceCodeCOMUNE_RESIDENZA_${memberId} = selectedOptionTextCOMUNE_RESIDENZA_${memberId}.split(', ')[1];
// Set the hidden field value hiddenFieldCOMUNE_RESIDENZA_${memberId}.value = provinceCodeCOMUNE_RESIDENZA_${memberId}; }); }
const newSelectElementsnascita_${memberId} = document.querySelectorAll('#comune_nascita_${memberId}'); const newStateElementnascita_${memberId} = document.querySelector('#stato_nascita_${memberId}');
// Unique function for the new elements const updateRequiredAttributeForNewElementsnascita_${memberId} = () => { if (newStateElementnascita_${memberId}.value !== '100000100') { newSelectElementsnascita_${memberId}.forEach(element => { element.removeAttribute('required'); element.setAttribute('disabled', true); }); } else { newSelectElementsnascita_${memberId}.forEach(element => { element.setAttribute('required', true); element.removeAttribute('disabled'); }); } };
// Initial call to set the correct required attribute state updateRequiredAttributeForNewElementsnascita_${memberId}();
// Event listener for the new state element newStateElementnascita_${memberId}.addEventListener('change', updateRequiredAttributeForNewElementsnascita_${memberId});
const newSelectElementsRESIDENZA_${memberId} = document.querySelectorAll('#COMUNE_RESIDENZA_${memberId}'); const newStateElementRESIDENZA_${memberId} = document.querySelector('#stato_RESIDENZA_${memberId}');
// Unique function for the new elements const updateRequiredAttributeForNewElementsRESIDENZA_${memberId} = () => { if (newStateElementRESIDENZA_${memberId}.value !== '100000100') { newSelectElementsRESIDENZA_${memberId}.forEach(element => { element.removeAttribute('required'); element.setAttribute('disabled', true); }); } else { newSelectElementsRESIDENZA_${memberId}.forEach(element => { element.setAttribute('required', true); element.removeAttribute('disabled'); }); } };
// Initial call to set the correct required attribute state updateRequiredAttributeForNewElementsRESIDENZA_${memberId}();
// Event listener for the new state element newStateElementRESIDENZA_${memberId}.addEventListener('change', updateRequiredAttributeForNewElementsRESIDENZA_${memberId});
const mainArrivo${memberId} = document.getElementById('data_arrivo'); const mainPartenza${memberId} = document.getElementById('data_partenza');
// Function to update the member dates const updateMemberDates${memberId} = () => { // Get the member date inputs const memberArrivo${memberId} = document.getElementById('data_arrivo_${memberId}'); const memberPartenza${memberId} = document.getElementById('data_partenza_${memberId}');
// Set the same date and disable the inputs memberArrivo${memberId}.value = mainArrivo${memberId}.value; memberArrivo${memberId}.setAttribute('readonly', true); memberPartenza${memberId}.value = mainPartenza${memberId}.value; memberPartenza${memberId}.setAttribute('readonly', true); };
// Attach event listeners to main date inputs mainArrivo${memberId}.addEventListener('change', updateMemberDates${memberId}); mainPartenza${memberId}.addEventListener('change', updateMemberDates${memberId});
// Initial update updateMemberDates${memberId}(); `;
const scriptElement = document.createElement('script'); scriptElement.textContent = scriptContent;
memberDiv.appendChild(scriptElement);
memberSections.appendChild(memberDiv); memberId++;
// Attach event listener to the remove button memberDiv.querySelector('.removeMemberBtn').addEventListener('click', () => { memberSections.removeChild(memberDiv); memberId--; adjustAddMemberButton(); });
adjustAddMemberButton(); }
function adjustAddMemberButton() { const addMemberContainer = document.getElementById('addMemberContainer'); const memberSections = document.getElementById('memberSections');
if (memberSections.children.length > 0) { memberSections.appendChild(addMemberContainer); } else { document.querySelector('form').insertBefore(addMemberContainer, document.querySelector('form').lastElementChild); } }
document.getElementById('addMemberBtn').addEventListener('click', addMemberSection);
document.getElementById('upload_document').addEventListener('change', function () { const fileList = document.getElementById('fileList'); fileList.innerHTML = ''; for (let i = 0; i < this.files.length; i++) { const li = document.createElement('li'); li.textContent = this.files[i].name; const removeButton = document.createElement('button'); removeButton.textContent = 'Remove'; removeButton.type = 'button'; removeButton.addEventListener('click', function () { fileList.removeChild(li); }); li.appendChild(removeButton); fileList.appendChild(li); } });