Enhance QuestionReviewForm layout with Bootstrap styling for status buttons and improve comment field presentation
This commit is contained in:
+4
-3
@@ -31,7 +31,7 @@ from generic.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||||
from django.forms.widgets import RadioSelect, TextInput, Textarea
|
from django.forms.widgets import RadioSelect, Textarea
|
||||||
|
|
||||||
from rapids.models import Rapid
|
from rapids.models import Rapid
|
||||||
from anatomy.models import AnatomyQuestion
|
from anatomy.models import AnatomyQuestion
|
||||||
@@ -840,8 +840,9 @@ class QuestionReviewForm(ModelForm):
|
|||||||
model = QuestionReview
|
model = QuestionReview
|
||||||
fields = ["status", "comment"]
|
fields = ["status", "comment"]
|
||||||
widgets = {
|
widgets = {
|
||||||
"status": RadioSelect(attrs={"class": "form-check-input"}),
|
# Use Bootstrap "btn-check" inputs so we can style labels as button toggles
|
||||||
"comment": TextInput(attrs={"class": "form-control form-control-sm", "placeholder": "Comment (optional)"}),
|
"status": RadioSelect(attrs={"class": "btn-check", "autocomplete": "off"}),
|
||||||
|
"comment": Textarea(attrs={"class": "form-control form-control-sm", "placeholder": "Comment (optional)", "rows": 2}),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -2,23 +2,44 @@
|
|||||||
hx-post="{% url app_name|add:':question_set_review' question.pk %}?edit=1"
|
hx-post="{% url app_name|add:':question_set_review' question.pk %}?edit=1"
|
||||||
hx-target="#question-review-block"
|
hx-target="#question-review-block"
|
||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
class="d-flex gap-2 align-items-start">
|
class="w-100">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="d-flex gap-2 align-items-center">
|
<div class="row g-2 align-items-start">
|
||||||
|
<div class="col-auto">
|
||||||
|
<label class="form-label mb-1">Status</label>
|
||||||
|
<div>
|
||||||
{% for radio in form.status %}
|
{% for radio in form.status %}
|
||||||
<div class="form-check form-check-inline">
|
{% comment %} Render colored button for each choice by checking value {% endcomment %}
|
||||||
{{ radio.tag }}
|
{{ radio.tag }}
|
||||||
<label class="form-check-label" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
{% if radio.choice_value == 'AC' %}
|
||||||
</div>
|
<label class="btn btn-outline-success me-1 mb-1" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
||||||
|
{% elif radio.choice_value == 'OD' %}
|
||||||
|
<label class="btn btn-outline-secondary me-1 mb-1" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
||||||
|
{% elif radio.choice_value == 'ER' %}
|
||||||
|
<label class="btn btn-outline-warning me-1 mb-1" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
||||||
|
{% elif radio.choice_value == 'RJ' %}
|
||||||
|
<label class="btn btn-outline-danger me-1 mb-1" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
||||||
|
{% else %}
|
||||||
|
<label class="btn btn-outline-primary me-1 mb-1" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if form.status.errors %}
|
||||||
<div>
|
<div class="invalid-feedback d-block">{{ form.status.errors|join:", " }}</div>
|
||||||
{{ form.comment }}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="col">
|
||||||
<button class="btn btn-sm btn-primary" type="submit">Save</button>
|
<label for="{{ form.comment.id_for_label }}" class="form-label mb-1">Comment</label>
|
||||||
|
{{ form.comment }}
|
||||||
|
{% if form.comment.errors %}
|
||||||
|
<div class="invalid-feedback d-block">{{ form.comment.errors|join:", " }}</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-auto d-flex align-items-end">
|
||||||
|
<button class="btn btn-primary" type="submit">Save</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
Reference in New Issue
Block a user