Skip to content

Commit c8e147e

Browse files
committed
forms: Selectize label input in update forms
This commit adds autocomplete similar to the filter autocomplete to labels field in patch details view (for users with project admin rights).
1 parent adb4e8a commit c8e147e

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

htdocs/css/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ select[class^=change-property-], .archive-patch-select, .add-bundle {
471471
margin: 0px 4px 0px 4px;
472472
}
473473

474+
.labels-field {
475+
padding: 4px;
476+
margin-right: 8px;
477+
box-sizing: border-box;
478+
border-radius: 4px;
479+
min-width: 200px;
480+
}
481+
474482
.patch-form-submit {
475483
font-weight: bold;
476484
padding: 4px;

patchwork/forms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ def __init__(self, instance=None, project=None, *args, **kwargs):
150150
Q(project=project) | Q(project=None)
151151
),
152152
required=False,
153+
widget=forms.SelectMultiple(
154+
attrs={'class': 'labels-field', 'placeholder': 'Labels'}
155+
),
153156
)
154157

155158
class Meta:
@@ -234,6 +237,9 @@ def __init__(self, project, *args, **kwargs):
234237
queryset=Label.objects.filter(
235238
Q(project=project) | Q(project=None)
236239
),
240+
widget=forms.SelectMultiple(
241+
attrs={'class': 'labels-field', 'placeholder': 'Labels to add'}
242+
),
237243
required=False,
238244
)
239245
self.fields['state'] = OptionalModelChoiceField(

patchwork/templates/patchwork/partials/patch-forms.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
{% load static %}
2+
3+
<script type="text/javascript">
4+
$(document).ready(function() {
5+
$('.labels-field').selectize({
6+
maxItems: null,
7+
persist: false,
8+
hideSelected: true,
9+
searchField: 'labels',
10+
});
11+
});
12+
</script>
13+
114
<div class="patch-forms" id="patch-forms">
215
{% if patch_form %}
316
<div id="patch-form-properties" class="patch-form">

0 commit comments

Comments
 (0)