Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 56 additions & 36 deletions js/address_change.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
// Set newSearch latch to false.
drupalSettings.centralHub.newSearch = false;

// Else make sure the select box is hidden.
// Else make sure the select box is hidden.
} else {
resetButton.addClass('hidden');
selectListContainer.addClass('hidden');
Expand All @@ -209,42 +209,62 @@
});
}
}
//pop up dropdown with searched address every time a Drupal AJAX request completes
$(document).ajaxComplete(function () {
var selectElement = $('.js-address-select');

// Clear previous options
selectElement.empty();

// Add default option
var defaultOption = $('<option>', {
value: '0',
text: '-Please choose an address-'
});
selectElement.append(defaultOption);

// Check if address list exists
var addressList = drupalSettings.centralHub.addressList;

if (addressList && addressList.length > 0) {
$.each(addressList, function (index, address) {
var option = $('<option>', {
value: address.name,
text: address.display
//below code handles the logic for Address Lookup dropdown
$(document).ready(function () {
// Store references to the clicked fieldset and dropdown
var clickedFieldset = null;
var clickedDropdown = null;

// Log details when a fieldset is clicked
$('fieldset').click(function () {
clickedFieldset = $(this); // Store the clicked fieldset
});

// Log details when the search button is clicked
$('.js-address-searchbutton').click(function () {
// Store the dropdown related to the clicked button
clickedDropdown = $(this).closest('fieldset').find('.js-address-select');
});

// Handle the dropdown update after AJAX request
$(document).ajaxComplete(function () {
if (clickedDropdown) {
var selectElement = clickedDropdown; // Get the specific dropdown that was clicked

// Clear previous options
selectElement.empty();

// Add default option
var defaultOption = $('<option>', {
value: '0',
text: '-Please choose an address-'
});
selectElement.append(option);
});
} else {
var noAddressOption = $('<option>', {
value: '',
text: 'No addresses found'
});
selectElement.append(noAddressOption);
}
selectElement.append(defaultOption);

// Check if address list exists in drupalSettings
var addressList = drupalSettings.centralHub.addressList;

if (addressList && addressList.length > 0) {
// Add addresses to the dropdown
$.each(addressList, function (index, address) {
var option = $('<option>', {
value: address.name,
text: address.display
});
selectElement.append(option);
});
} else {
// If no addresses are found, show a "No addresses found" option
var noAddressOption = $('<option>', {
value: '',
text: 'No addresses found'
});
selectElement.append(noAddressOption);
}

// Show the dropdown after AJAX loads addresses
$('.js-address-select-container').removeClass('hidden');
// Show the dropdown after AJAX loads addresses
selectElement.closest('.js-address-select-container').removeClass('hidden');
}
});
});


})(jQuery, Drupal);
Loading