Replace choice field with integer field for rating

main
Luca 2 years ago
parent de064195ff
commit 78f79646d1

@ -223,14 +223,3 @@ svg {
.row > :not(:first-child) {
margin-left: 0.5em !important;
}
.row > .rating-container {
justify-content: center;
margin: 0;
padding: 0;
}
.row > .rating-container > .rating > .rating-point {
height: 1em;
width: 1em;
}

@ -3,7 +3,7 @@ from django.conf import settings
class InsertForm(forms.Form):
name = forms.CharField()
rating = forms.ChoiceField(choices=settings.RATING_CHOICES, required=False, widget=forms.RadioSelect)
rating = forms.IntegerField(max_value=10, min_value=1, required=False)
InsertFormSet = forms.formset_factory(InsertForm)

@ -10,18 +10,9 @@
{% for form in formset %}
<div class="row">
{{ form.name }}
<div class="rating-container">
<div class="rating" style="--num-choices: {{ form.rating | length }}">
{% for radio in form.rating %}
{{ radio.tag }}
<label class="rating-point" for="{{ radio.id_for_label }}"></label>
{% for field in form %}
{{ field }}
{% endfor %}
</div>
</div>
<button class="reset" type="button">Zurücksetzen</button>
</div>
{% endfor %}
@ -76,10 +67,10 @@ const registerEvents = row => {
}
});
row.querySelector('.reset').addEventListener('click', event => {
event.target.parentElement.querySelectorAll('.rating-container > .rating > input').forEach(input => {
input.checked = false;
});
row.querySelector('input[name$=rating]').addEventListener('keydown', event => {
if (event.key === 'Enter') {
event.preventDefault();
}
});
};
document.querySelectorAll('.row').forEach(registerEvents);
@ -110,9 +101,7 @@ addBtn.addEventListener('click', () => {
input.dataset.bestMatch = '';
input.dataset.value = '';
row.querySelectorAll('.rating-container > .rating > input').forEach(input => {
input.checked = false;
});
row.querySelector('input[name$=rating]').value = undefined;
registerEvents(row);

@ -59,7 +59,10 @@ def insert(request, session):
artist = get_object_or_404(Artist, name=form.cleaned_data['name'])
rating = Rating(artist=artist, participant=participant, value=form.cleaned_data['rating'])
value = form.cleaned_data['rating']
value = str(value) if value else ''
rating = Rating(artist=artist, participant=participant, value=value)
rating.save()
formset = InsertFormSet() # clear formset if successful

Loading…
Cancel
Save