Issue#26 fix.

This commit is contained in:
AppleGrew (applegrew) 2013-02-28 21:17:20 +05:30
parent 4e1243bfec
commit b39268f42d
2 changed files with 7 additions and 1 deletions

View file

@ -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)

View file

@ -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