mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-25 10:11:08 -05:00
71 lines
2.7 KiB
HTML
71 lines
2.7 KiB
HTML
<div class="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;"
|
|
x-data="manufacturerSearchResults('{{ submission_id }}')"
|
|
@click.outside="clearResults()">
|
|
{% if manufacturers %}
|
|
{% for manufacturer in manufacturers %}
|
|
<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="selectManufacturer('{{ manufacturer.id }}', '{{ manufacturer.name|escapejs }}')">
|
|
{{ manufacturer.name }}
|
|
</button>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="px-4 py-2 text-gray-700 dark:text-gray-300">
|
|
{% if search_term %}
|
|
No manufacturers found
|
|
{% else %}
|
|
Start typing to search...
|
|
{% endif %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('alpine:init', () => {
|
|
Alpine.data('manufacturerSearchResults', (submissionId) => ({
|
|
submissionId: submissionId,
|
|
|
|
selectManufacturer(id, name) {
|
|
// Debug logging
|
|
console.log('Selecting manufacturer:', {id, name, submissionId: this.submissionId});
|
|
|
|
// Find elements using AlpineJS approach
|
|
const manufacturerInput = document.querySelector(`#manufacturer-input-${this.submissionId}`);
|
|
const searchInput = document.querySelector(`#manufacturer-search-${this.submissionId}`);
|
|
const resultsDiv = document.querySelector(`#manufacturer-search-results-${this.submissionId}`);
|
|
|
|
// Debug logging
|
|
console.log('Found elements:', {
|
|
manufacturerInput: manufacturerInput?.id,
|
|
searchInput: searchInput?.id,
|
|
resultsDiv: resultsDiv?.id
|
|
});
|
|
|
|
// Update hidden input
|
|
if (manufacturerInput) {
|
|
manufacturerInput.value = id;
|
|
console.log('Updated manufacturer input value:', manufacturerInput.value);
|
|
}
|
|
|
|
// Update search input
|
|
if (searchInput) {
|
|
searchInput.value = name;
|
|
console.log('Updated search input value:', searchInput.value);
|
|
}
|
|
|
|
// Clear results
|
|
this.clearResults();
|
|
},
|
|
|
|
clearResults() {
|
|
const resultsDiv = document.querySelector(`#manufacturer-search-results-${this.submissionId}`);
|
|
if (resultsDiv) {
|
|
resultsDiv.innerHTML = '';
|
|
console.log('Cleared results div');
|
|
}
|
|
}
|
|
}));
|
|
});
|
|
</script>
|