From 102fbdb880309f9eb59a60cad21a887b347adffd Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 20 Apr 2025 22:03:21 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20UX=20recherche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/static/style.scss | 20 ++++++++++- .../agenda_culturel/place_unknown_form.html | 34 +++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index c0d774f..7021d67 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -1457,6 +1457,24 @@ img.preview { transform: rotate(0); } } + + + .choices__input-wrapper { + position: relative; + } + + .clear-btn { + position: absolute; + width: 3em; + right: 0.5em; + top: 1.3em; + transform: translateY(-50%); + background: transparent; + border: none; + font-size: 16px; + cursor: pointer; + z-index: 10; + } } .choices[data-type=select-multiple] { @@ -1519,8 +1537,8 @@ img.preview { .choices__list--dropdown.is-active .choices__group { display: block; } -} +} diff --git a/src/agenda_culturel/templates/agenda_culturel/place_unknown_form.html b/src/agenda_culturel/templates/agenda_culturel/place_unknown_form.html index 1aaf9de..24a4e75 100644 --- a/src/agenda_culturel/templates/agenda_culturel/place_unknown_form.html +++ b/src/agenda_culturel/templates/agenda_culturel/place_unknown_form.html @@ -59,8 +59,38 @@ setTimeout(() => { const searchTerm = '{{ object.location }}'; choices.input.focus(); - choices.input.value = searchTerm; // Met à jour le champ de recherche visible - choices._handleSearch(searchTerm); // Force la recherche + choices.input.value = searchTerm; + choices._handleSearch(searchTerm); + + const inputWrapper = choices.input.element.parentElement; + console.log(choices.input.element); + console.log(inputWrapper); + var clearBtn; + if (inputWrapper) { + inputWrapper.classList.add('choices__input-wrapper'); + + clearBtn = document.createElement('button'); + clearBtn.innerHTML = '×'; + clearBtn.className = 'clear-btn'; + clearBtn.addEventListener('click', (e) => { + e.preventDefault(); + const input = inputWrapper.querySelector('.choices__input'); + if (input) input.value = ''; + clearBtn.style.display = 'none'; + }); + + inputWrapper.appendChild(clearBtn); + if (choices.input.element) { + choices.input.element.addEventListener('input', () => { + clearBtn.style.display = choices.input.element.value ? 'block' : 'none'; + }); + + } + + } + + + }, 100);