From 3ad5726e7dd331376eb4268b9dcb1b29cb1f0b7b Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 3 Feb 2009 23:00:14 +0100 Subject: [PATCH] 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. --- tools/widgets/dropdownmultiple.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) -- 2.30.2