.
This commit is contained in:
+5
-4
@@ -828,10 +828,11 @@ class UserAutocomplete(ModelAutocomplete):
|
||||
search_attrs = ["first_name", "last_name", "username"]
|
||||
|
||||
class UsersAutocompleteForm(Form):
|
||||
users = ModelChoiceField(queryset=User.objects.all(), widget=AutocompleteWidget(
|
||||
ac_class=UserAutocomplete, options={"multiselect": True}
|
||||
|
||||
))
|
||||
# Use a ModelMultipleChoiceField so the widget's multiselect option maps to a multi-value field
|
||||
users = ModelMultipleChoiceField(
|
||||
queryset=User.objects.all(),
|
||||
widget=AutocompleteWidget(ac_class=UserAutocomplete, options={"multiselect": True}),
|
||||
)
|
||||
|
||||
autocomplete_register(UserAutocomplete)
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{{ form.media }}
|
||||
<form hx-post="{% url 'generic:exam_collection_add_author' collection_id %}" hx-target="#add-user" hx-swap="innerHTML" hx-indicator="#add-author-indicator" action="" method="post" enctype="multipart/form-data" id="user-form" class="inline-form">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|crispy }}
|
||||
{% comment %} Use a normal submit so the form data is included in the HTMX request {% endcomment %}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
|
||||
<span id="add-author-indicator" class="ms-2" aria-hidden="true">
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||
</span>
|
||||
|
||||
</form>
|
||||
|
||||
<style>
|
||||
/* Hide indicator by default; HTMX will add the `htmx-request` class during requests */
|
||||
#add-author-indicator { display: none; }
|
||||
#add-author-indicator.htmx-request { display: inline-flex; align-items: center; }
|
||||
</style>
|
||||
+2
-1
@@ -5165,9 +5165,10 @@ def exam_collection_add_author(request, collection_id):
|
||||
if request.method != "POST":
|
||||
form = UsersAutocompleteForm()
|
||||
|
||||
# Render the fixed form which properly includes form data in HTMX POSTs
|
||||
return render(
|
||||
request,
|
||||
"generic/user_form.html",
|
||||
"generic/user_form_fixed.html",
|
||||
{"form": form, "collection_id": collection_id},
|
||||
)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user