mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 03:51:09 -05:00
43 lines
1.8 KiB
HTML
43 lines
1.8 KiB
HTML
<script>
|
|
document.addEventListener('alpine:init', () => {
|
|
Alpine.data('designerSearchResults', () => ({
|
|
selectDesigner(id, name) {
|
|
// Update designer fields using AlpineJS reactive approach
|
|
const designerInput = this.$el.closest('form').querySelector('#id_designer');
|
|
const searchInput = this.$el.closest('form').querySelector('#id_designer_search');
|
|
const resultsDiv = this.$el.closest('form').querySelector('#designer-search-results');
|
|
|
|
if (designerInput) designerInput.value = id;
|
|
if (searchInput) searchInput.value = name;
|
|
if (resultsDiv) resultsDiv.innerHTML = '';
|
|
|
|
// Dispatch custom event for parent component
|
|
this.$dispatch('designer-selected', { id, name });
|
|
}
|
|
}));
|
|
});
|
|
</script>
|
|
|
|
<div x-data="designerSearchResults()"
|
|
@click.outside="$el.innerHTML = ''"
|
|
class="absolute z-50 w-full mt-1 bg-white border border-gray-300 rounded-lg shadow-lg dark:bg-gray-700 dark:border-gray-600"
|
|
style="max-height: 240px; overflow-y: auto;">
|
|
{% if designers %}
|
|
{% for designer in designers %}
|
|
<button type="button"
|
|
class="w-full px-4 py-2 text-left text-gray-900 hover:bg-gray-100 dark:text-white dark:hover:bg-gray-600"
|
|
@click="selectDesigner('{{ designer.id }}', '{{ designer.name|escapejs }}')">
|
|
{{ designer.name }}
|
|
</button>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="px-4 py-2 text-gray-700 dark:text-gray-300">
|
|
{% if search_term %}
|
|
No matches found. You can still submit this name.
|
|
{% else %}
|
|
Start typing to search...
|
|
{% endif %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|