Skip to content

Commit

Permalink
use auto submit behavior for user select
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker committed Sep 16, 2024
1 parent f5a38c2 commit 382b6db
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bookmarks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class BookmarkSearchForm(forms.Form):
]

q = forms.CharField()
user = forms.ChoiceField()
user = forms.ChoiceField(required=False)
sort = forms.ChoiceField(choices=SORT_CHOICES)
shared = forms.ChoiceField(choices=FILTER_SHARED_CHOICES, widget=forms.RadioSelect)
unread = forms.ChoiceField(choices=FILTER_UNREAD_CHOICES, widget=forms.RadioSelect)
Expand Down
11 changes: 1 addition & 10 deletions bookmarks/templates/bookmarks/user_select.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
{% endfor %}
<div class="form-group">
<div class="d-flex">
{{ form.user|add_class:"form-select" }}
{% render_field form.user class+="form-select" ld-auto-submit="" %}
<noscript>
<button type="submit" class="btn btn-link ml-2">Apply</button>
</noscript>
</div>
</div>
</form>
<script>
(function init() {
const form = document.getElementById('user-select');
const select = form.querySelector('select');
select.addEventListener('change', () => {
form.submit();
});
})();
</script>
2 changes: 1 addition & 1 deletion bookmarks/tests/test_bookmark_shared_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def assertVisibleUserOptions(self, response, users: List[User]):
f'<option value="{user.username}">{user.username}</option>'
)
user_select_html = f"""
<select name="user" class="form-select" required="" id="id_user">
<select name="user" class="form-select" id="id_user" ld-auto-submit>
{''.join(user_options)}
</select>
"""
Expand Down

0 comments on commit 382b6db

Please sign in to comment.