mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 13:18:25 +02:00
Add autocomplete feature for jury form
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -8,15 +8,15 @@
|
||||
|
||||
{% for jury in pool.juries.all %}
|
||||
<div class="row my-3">
|
||||
<div class="col-md-5">
|
||||
<input type="email" class="form-control" value="{{ jury.user.email }}" disabled>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<input type="text" class="form-control" value="{{ jury.user.first_name }}" disabled>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<input type="text" class="form-control" value="{{ jury.user.last_name }}" disabled>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="email" class="form-control" value="{{ jury.user.email }}" disabled>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<a href="{% url 'participation:pool_remove_jury' pk=pool.pk jury_id=jury.id %}" class="btn btn-danger">
|
||||
Retirer
|
||||
@ -28,6 +28,15 @@
|
||||
{{ form|as_crispy_errors }}
|
||||
{% crispy form %}
|
||||
|
||||
<datalist id="juries-email">
|
||||
</datalist>
|
||||
|
||||
<datalist id="juries-first-name">
|
||||
</datalist>
|
||||
|
||||
<datalist id="juries-last-name">
|
||||
</datalist>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="row text-center">
|
||||
@ -39,8 +48,60 @@
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initModal("updatePool", "{% url "participation:pool_update" pk=pool.pk %}")
|
||||
const emailField = document.getElementById('id_email')
|
||||
const firstNameField = document.getElementById('id_first_name')
|
||||
const lastNameField = document.getElementById('id_last_name')
|
||||
|
||||
const juriesEmailList = document.getElementById('juries-email')
|
||||
const juriesFirstNameList = document.getElementById('juries-first-name')
|
||||
const juriesLastNameList = document.getElementById('juries-last-name')
|
||||
|
||||
function updateJuries(filter) {
|
||||
fetch(`/api/registration/volunteers/?search=${filter}`)
|
||||
.then(response => response.json())
|
||||
.then(response => response.results)
|
||||
.then(data => {
|
||||
juriesEmailList.innerHTML = ''
|
||||
juriesFirstNameList.innerHTML = ''
|
||||
juriesLastNameList.innerHTML = ''
|
||||
|
||||
data.forEach(jury => {
|
||||
const optionEmail = document.createElement('option')
|
||||
optionEmail.value = jury.email
|
||||
optionEmail.setAttribute('data-id', jury.id)
|
||||
juriesEmailList.appendChild(optionEmail)
|
||||
|
||||
const optionFirstName = document.createElement('option')
|
||||
optionFirstName.value = jury.first_name
|
||||
optionFirstName.setAttribute('data-id', jury.id)
|
||||
juriesFirstNameList.appendChild(optionFirstName)
|
||||
|
||||
const optionLastName = document.createElement('option')
|
||||
optionLastName.value = jury.last_name
|
||||
optionLastName.setAttribute('data-id', jury.id)
|
||||
juriesLastNameList.appendChild(optionLastName)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
emailField.addEventListener('input', event => {
|
||||
let emailOption = document.querySelector(`datalist[id="juries-email"] > option[value="${event.target.value}"]`)
|
||||
if (emailOption) {
|
||||
let id = emailOption.getAttribute('data-id')
|
||||
let firstNameOption = document.querySelector(`datalist[id="juries-first-name"] > option[data-id="${id}"]`)
|
||||
let lastNameOption = document.querySelector(`datalist[id="juries-last-name"] > option[data-id="${id}"]`)
|
||||
if (firstNameOption && lastNameOption) {
|
||||
firstNameField.value = firstNameOption.value
|
||||
lastNameField.value = lastNameOption.value
|
||||
}
|
||||
}
|
||||
updateJuries(event.target.value)
|
||||
})
|
||||
firstNameField.addEventListener('input', event => {
|
||||
updateJuries(event.target.value)
|
||||
})
|
||||
lastNameField.addEventListener('input', event => {
|
||||
updateJuries(event.target.value)
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user