Skip to content

Commit

Permalink
Fix bug in sound edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Nov 22, 2023
1 parent 58b5216 commit bee2640
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sounds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ def __init__(self, *args, **kwargs):
# Prepare pack field
if user_packs:
user_packs = user_packs.extra(select={'lower_name': 'lower(name)'}).order_by('lower_name')
self.fields['pack'].choices = [(PackForm.NO_PACK_CHOICE_VALUE, '--- No pack ---'),
(PackForm.NEW_PACK_CHOICE_VALUE, 'Create a new pack...')] + \
([(pack.id, pack.name) for pack in user_packs] if user_packs else [])
# The attrs below are used so that some elements of the dropdown are displayed in gray and to enable
# pre-selecting options using keyboard
self.fields['pack'].widget.attrs = {'data-grey-items': f'{PackForm.NO_PACK_CHOICE_VALUE},{PackForm.NEW_PACK_CHOICE_VALUE}',
'data-select-with-keyboard': True}
else:
user_packs = []
self.fields['pack'].choices = [(PackForm.NO_PACK_CHOICE_VALUE, '--- No pack ---'),
(PackForm.NEW_PACK_CHOICE_VALUE, 'Create a new pack...')] + \
([(pack.id, pack.name) for pack in user_packs] if user_packs else [])
# The attrs below are used so that some elements of the dropdown are displayed in gray and to enable
# pre-selecting options using keyboard
self.fields['pack'].widget.attrs = {'data-grey-items': f'{PackForm.NO_PACK_CHOICE_VALUE},{PackForm.NEW_PACK_CHOICE_VALUE}',
'data-select-with-keyboard': True}

def clean(self):
data = self.cleaned_data
Expand Down

0 comments on commit bee2640

Please sign in to comment.