mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-22 23:42:25 +00:00
🎨 Better autocomplete field
This commit is contained in:
parent
5b3361f086
commit
d95cd8c7c7
@ -54,7 +54,7 @@ class UserViewSet(ReadProtectedModelViewSet):
|
||||
serializer_class = UserSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['id', 'username', 'first_name', 'last_name', 'email', 'is_superuser', 'is_staff', 'is_active', ]
|
||||
search_fields = ['$username', '$first_name', '$last_name', ]
|
||||
search_fields = ['$username', '$first_name', '$last_name', '$note__alias__name', '$note__alias__normalized_name', ]
|
||||
|
||||
|
||||
# This ViewSet is the only one that is accessible from all authenticated users!
|
||||
|
@ -326,8 +326,8 @@ class ClubListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||
|
||||
qs = qs.filter(
|
||||
Q(name__iregex=pattern)
|
||||
| Q(note__alias__name__iregex="^" + pattern)
|
||||
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
|
||||
| Q(note__alias__name__iregex=pattern)
|
||||
| Q(note__alias__normalized_name__iregex=Alias.normalize(pattern))
|
||||
)
|
||||
|
||||
return qs
|
||||
|
@ -10,6 +10,8 @@ $(document).ready(function () {
|
||||
if (!name_field)
|
||||
name_field = "name";
|
||||
let input = target.val();
|
||||
target.addClass("is-invalid");
|
||||
target.removeClass("is-valid");
|
||||
$("#" + prefix + "_reset").removeClass("d-none");
|
||||
|
||||
$.getJSON(api_url + (api_url.includes("?") ? "&" : "?") + "format=json&search=^" + input + api_url_suffix, function(objects) {
|
||||
@ -27,6 +29,10 @@ $(document).ready(function () {
|
||||
target.val(obj[name_field]);
|
||||
$("#" + prefix + "_pk").val(obj.id);
|
||||
|
||||
results_list.html("");
|
||||
target.removeClass("is-invalid");
|
||||
target.addClass("is-valid");
|
||||
|
||||
if (typeof autocompleted != 'undefined')
|
||||
autocompleted(obj, prefix)
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user