mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 09:31:09 -05:00
Refactor photo management and upload functionality to use HTMX for asynchronous requests
- Updated photo upload handling in `photo_manager.html` and `photo_upload.html` to utilize HTMX for file uploads, improving user experience and reducing reliance on Promises. - Refactored caption update and primary photo toggle methods to leverage HTMX for state updates without full page reloads. - Enhanced error handling and success notifications using HTMX events. - Replaced fetch API calls with HTMX forms in various templates, including `homepage.html`, `park_form.html`, and `roadtrip_planner.html`, to streamline AJAX interactions. - Improved search suggestion functionality in `search_script.html` by implementing HTMX for fetching suggestions, enhancing performance and user experience. - Updated designer, manufacturer, and ride model forms to handle responses with HTMX, ensuring better integration and user feedback.
This commit is contained in:
@@ -123,18 +123,30 @@ Features:
|
||||
if (search.length >= 2) {
|
||||
{% if autocomplete_url %}
|
||||
loading = true;
|
||||
fetch('{{ autocomplete_url }}?q=' + encodeURIComponent(search))
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
||||
// Create temporary form for HTMX request
|
||||
const tempForm = document.createElement('form');
|
||||
tempForm.setAttribute('hx-get', '{{ autocomplete_url }}');
|
||||
tempForm.setAttribute('hx-vals', JSON.stringify({q: search}));
|
||||
tempForm.setAttribute('hx-trigger', 'submit');
|
||||
tempForm.setAttribute('hx-swap', 'none');
|
||||
|
||||
tempForm.addEventListener('htmx:afterRequest', (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.detail.xhr.responseText);
|
||||
suggestions = data.suggestions || [];
|
||||
open = suggestions.length > 0;
|
||||
loading = false;
|
||||
selectedIndex = -1;
|
||||
})
|
||||
.catch(() => {
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
open = false;
|
||||
});
|
||||
}
|
||||
document.body.removeChild(tempForm);
|
||||
});
|
||||
|
||||
document.body.appendChild(tempForm);
|
||||
htmx.trigger(tempForm, 'submit');
|
||||
{% endif %}
|
||||
} else {
|
||||
open = false;
|
||||
|
||||
Reference in New Issue
Block a user