mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-05-10 14:24:45 +00:00
Issue#26 fix.
This commit is contained in:
parent
4e1243bfec
commit
b39268f42d
2 changed files with 7 additions and 1 deletions
|
|
@ -231,7 +231,11 @@ class Select2Widget(Select2Mixin, forms.Select):
|
|||
self.options.pop('multiple', None)
|
||||
|
||||
def render_options(self, choices, selected_choices):
|
||||
if not self.is_required:
|
||||
all_choices = chain(self.choices, choices)
|
||||
if not self.is_required and \
|
||||
len([value for value, txt in all_choices if value == '']) == 0: # Checking if list already has empty choice
|
||||
# as in the case of Model based Light fields.
|
||||
|
||||
choices = list(choices)
|
||||
choices.append(('', '', )) # Adding an empty choice
|
||||
return super(Select2Widget, self).render_options(choices, selected_choices)
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ class MixedForm(forms.Form):
|
|||
always_fail_rooms_multi = ClassRoomChoices(validators=[validate_fail_always])
|
||||
always_fail_self_choice = SelfChoices(validators=[validate_fail_always], auto_id='always_fail_self_choice')
|
||||
always_fail_self_choice_multi = SelfMultiChoices(validators=[validate_fail_always], auto_id='always_fail_self_choice_multi')
|
||||
model_with_both_required_and_empty_label_false = ModelSelect2Field(
|
||||
queryset=Employee.objects, empty_label=None, required=False) #issue#26
|
||||
|
||||
# These are just for testing Auto registration of fields
|
||||
EmployeeChoices() # Should already be registered
|
||||
|
|
|
|||
Loading…
Reference in a new issue