From 7afc5832826abbdb3aa828a1f9705495236be8bb Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 29 Apr 2022 01:40:43 +0200 Subject: [PATCH] Made trust adding widget resetable, corrected the unexpected empty field behavior and improved autocomplete's responsiveness --- apps/member/views.py | 3 +-- note_kfet/static/js/autocomplete_model.js | 15 +++++++++------ note_kfet/templates/autocomplete_model.html | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index a41b0bff..2bc2133c 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -266,11 +266,10 @@ class ProfileTrustView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): )) context["widget"] = { "name": "trusted", + "resetable": True, "attrs": { - "model_pk": ContentType.objects.get_for_model(Alias).pk, "class": "autocomplete form-control", "id": "trusted", - "resetable": True, "api_url": "/api/note/alias/?note__polymorphic_ctype__model=noteuser", "name_field": "name", "placeholder": "" diff --git a/note_kfet/static/js/autocomplete_model.js b/note_kfet/static/js/autocomplete_model.js index 2a2677d4..a8b2461c 100644 --- a/note_kfet/static/js/autocomplete_model.js +++ b/note_kfet/static/js/autocomplete_model.js @@ -1,3 +1,5 @@ +const keycodes = [32, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 106, 107, 109, 110, 111, 186, 187, 188, 189, 190, 191, 219, 220, 221, 222] + $(document).ready(function () { $('.autocomplete').keyup(function (e) { const target = $('#' + e.target.id) @@ -10,7 +12,6 @@ $(document).ready(function () { const 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) { let html = '