mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:31:09 -05:00
Refactor ride model form to remove legacy JavaScript functions. Streamlined event handling by leveraging Alpine.js for improved state management and user experience.
This commit is contained in:
@@ -225,49 +225,3 @@ document.addEventListener('alpine:init', () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
|
||||||
function selectManufacturer(manufacturerId, manufacturerName) {
|
|
||||||
// Update the hidden manufacturer field
|
|
||||||
document.getElementById('id_manufacturer').value = manufacturerId;
|
|
||||||
// Update the search input with the manufacturer name
|
|
||||||
document.getElementById('id_manufacturer_search').value = manufacturerName;
|
|
||||||
// Clear the search results
|
|
||||||
document.getElementById('manufacturer-search-results').innerHTML = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close search results when clicking outside
|
|
||||||
document.addEventListener('click', function(event) {
|
|
||||||
// Get the parent form element that contains the Alpine.js data
|
|
||||||
const formElement = event.target.closest('form[x-data]');
|
|
||||||
if (!formElement) return;
|
|
||||||
|
|
||||||
// Get Alpine.js data from the form
|
|
||||||
const formData = formElement.__x.$data;
|
|
||||||
|
|
||||||
// Don't handle clicks if manufacturer modal is open
|
|
||||||
if (formData.showManufacturerModal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchResults = [
|
|
||||||
{ input: 'id_manufacturer_search', results: 'manufacturer-search-results' }
|
|
||||||
];
|
|
||||||
|
|
||||||
searchResults.forEach(function(item) {
|
|
||||||
const input = document.getElementById(item.input);
|
|
||||||
const results = document.getElementById(item.results);
|
|
||||||
if (results && !results.contains(event.target) && event.target !== input) {
|
|
||||||
results.innerHTML = '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initialize form with any pre-filled values
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
const searchInput = document.getElementById('id_ride_model_search');
|
|
||||||
if (searchInput && searchInput.value) {
|
|
||||||
document.getElementById('id_name').value = searchInput.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user