Browse Source

feat(choix pondérés): averti en cas de dépassement de quota

pull/52/head
François Poulain 8 months ago
parent
commit
39ebb439b4
  1. 7
      assets/js/ponderated.js
  2. 15
      assets/scss/ponderated.scss
  3. 3
      gvot/templates/django/forms/widgets/ponderatedwidget.html

7
assets/js/ponderated.js

@ -12,6 +12,8 @@ $(() => {
const wrapper = $(elem);
const remaining = wrapper.find('.ponderatedwidget--remaining');
const available = wrapper.find('.ponderatedwidget--available');
const warning = wrapper.find('.ponderatedwidget--warning');
const error = wrapper.parent().find('.invalid-feedback:contains(mandats disponibles)');
const inputs = wrapper.find('input');
$(inputs).on('change', () => {
const availableInt = Number(available[0].textContent);
@ -21,6 +23,11 @@ $(() => {
}, 0);
if (availableInt - affected >= 0) {
remaining[0].textContent = availableInt - affected;
$(error).addClass('d-none');
$(warning).addClass('d-none');
} else {
$(error).removeClass('d-none');
$(warning).removeClass('d-none');
}
});
});

15
assets/scss/ponderated.scss

@ -4,6 +4,17 @@
display: block;
}
.ponderatedwidget input {
width: 7em;
.has-errors > .ponderatedwidget > .ponderatedwidget--warning {
display: none;
}
.ponderatedwidget {
input {
width: 7em;
}
.ponderatedwidget--warning {
margin-top: .25rem;
font-size: 80%;
color: #dc3545;
}
}

3
gvot/templates/django/forms/widgets/ponderatedwidget.html

@ -7,4 +7,7 @@
<table>
{% include 'django/forms/widgets/multiwidget.html' %}
</table>
<div class="ponderatedwidget--warning d-none">
Vous ne pouvez pas affecter plus de choix que le nombre de mandats disponibles.
</div>
</div>

Loading…
Cancel
Save
Map all the world