Add autocomplete to labels field of update form in the patch details
view (only visible for users with project admin rights).

Signed-off-by: Franciszek Stachura <[email protected]>
---
 htdocs/css/style.css                                |  8 ++++++++
 patchwork/forms.py                                  |  6 ++++++
 .../templates/patchwork/partials/patch-forms.html   | 13 +++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/htdocs/css/style.css b/htdocs/css/style.css
index 268a8c37..db3a066c 100644
--- a/htdocs/css/style.css
+++ b/htdocs/css/style.css
@@ -471,6 +471,14 @@ select[class^=change-property-], .archive-patch-select, 
.add-bundle {
     margin: 0px 4px 0px 4px;
 }
 
+.labels-field {
+    padding: 4px;
+    margin-right: 8px;
+    box-sizing: border-box;
+    border-radius: 4px;
+    min-width: 200px;
+}
+
 .patch-form-submit {
     font-weight: bold;
     padding: 4px;
diff --git a/patchwork/forms.py b/patchwork/forms.py
index 19d19d64..39481283 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -150,6 +150,9 @@ class PatchForm(forms.ModelForm):
                 Q(project=project) | Q(project=None)
             ),
             required=False,
+            widget=forms.SelectMultiple(
+                attrs={'class': 'labels-field', 'placeholder': 'Labels'}
+            ),
         )
 
     class Meta:
@@ -234,6 +237,9 @@ class MultiplePatchForm(forms.Form):
             queryset=Label.objects.filter(
                 Q(project=project) | Q(project=None)
             ),
+            widget=forms.SelectMultiple(
+                attrs={'class': 'labels-field', 'placeholder': 'Labels to add'}
+            ),
             required=False,
         )
         self.fields['state'] = OptionalModelChoiceField(
diff --git a/patchwork/templates/patchwork/partials/patch-forms.html 
b/patchwork/templates/patchwork/partials/patch-forms.html
index 2dee8230..1722a931 100644
--- a/patchwork/templates/patchwork/partials/patch-forms.html
+++ b/patchwork/templates/patchwork/partials/patch-forms.html
@@ -1,3 +1,16 @@
+{% load static %}
+
+<script type="text/javascript">
+$(document).ready(function() {
+    $('.labels-field').selectize({
+        maxItems: null,
+        persist: false,
+        hideSelected: true,
+        searchField: 'labels',
+    });
+});
+</script>
+
 <div class="patch-forms" id="patch-forms">
 {% if patch_form %}
   <div id="patch-form-properties" class="patch-form">
-- 
2.55.0

_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to