Skip to content

Commit 180ac89

Browse files
committed
Add selectize support to tag picker
1 parent 02aa97f commit 180ac89

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

pgcommitfest/commitfest/forms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class PatchForm(forms.ModelForm):
7272
selectize_fields = {
7373
"authors": "/lookups/user",
7474
"reviewers": "/lookups/user",
75+
"tags": None,
7576
}
7677

7778
class Meta:
@@ -94,8 +95,14 @@ def __init__(self, *args, **kwargs):
9495
x.user.username,
9596
)
9697

98+
self.fields["authors"].widget.attrs["class"] = "add-user-picker"
99+
self.fields["reviewers"].widget.attrs["class"] = "add-user-picker"
100+
97101
# Selectize multiple fields -- don't pre-populate everything
98102
for field, url in list(self.selectize_fields.items()):
103+
if url is None:
104+
continue
105+
99106
# If this is a postback of a selectize field, it may contain ids that are not currently
100107
# stored in the field. They must still be among the *allowed* values of course, which
101108
# are handled by the existing queryset on the field.

pgcommitfest/commitfest/templates/base_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h3>Search user</h3>
7575
{%include "selectize_js.html" %}
7676
<script>
7777
{%if user.is_staff%}
78-
$('.selectize-control').after(
78+
$('.selectize-control.add-user-picker').after(
7979
$('<a href="#" class="btn btn-default btn-sm">Import user not listed</a>').click(function () {
8080
search_and_store_user();
8181
})

pgcommitfest/commitfest/templates/selectize_js.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
valueField: 'id',
66
labelField: 'value',
77
searchField: 'value',
8+
{%if url%}
89
load: function(query, callback) {
910
if (!query.length) return callback();
1011
$.ajax({
@@ -18,6 +19,7 @@
1819
'success': function(res) { callback(res.values);},
1920
});
2021
},
22+
{%endif%}
2123
onFocus: function() {
2224
if (this.$input.is('[multiple]')) {
2325
return;

0 commit comments

Comments
 (0)