From: Matthijs Kooijman Date: Tue, 3 Feb 2009 22:00:14 +0000 (+0100) Subject: Put the empty option on top in DropDownMultiple. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fxerxes.git;a=commitdiff_plain;h=3ad5726e7dd331376eb4268b9dcb1b29cb1f0b7b Put the empty option on top in DropDownMultiple. Previous changes that started reusing Select.render_options had the side effect of moving the empty option to the bottom. This restores the original behaviour. --- diff --git a/tools/widgets/dropdownmultiple.py b/tools/widgets/dropdownmultiple.py index 5bbe27e..10c7a2b 100644 --- a/tools/widgets/dropdownmultiple.py +++ b/tools/widgets/dropdownmultiple.py @@ -75,8 +75,12 @@ class DropDownMultiple(widgets.SelectMultiple): id = final_attrs['id'] del final_attrs['id'] - # Insert blank value - choices = [('','---')] + list(choices) + # Insert blank value. We insert this in self.choices, because + # render_options merges self.choices with its choices argument + # (in that order) and we want to have the empty option at the + # top. + old_choices = self.choices + self.choices = [('','---')] + list(self.choices) # Build values items = [] @@ -91,6 +95,9 @@ class DropDownMultiple(widgets.SelectMultiple): script = TPL_SCRIPT %{'id': id} output = TPL_FULL %{'id': id, 'values': '\n'.join(items), 'script': script} + + # Restore the original choices + self.choices = old_choices return mark_safe(output)