mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #28157 -- Fixed choice ordering in form fields with grouped and non-grouped options.
Regression in b52c73008a.
This commit is contained in:
@@ -547,25 +547,23 @@ class ChoiceWidget(Widget):
|
||||
|
||||
def optgroups(self, name, value, attrs=None):
|
||||
"""Return a list of optgroups for this widget."""
|
||||
default = (None, [], 0)
|
||||
groups = [default]
|
||||
groups = []
|
||||
has_selected = False
|
||||
|
||||
for option_value, option_label in chain(self.choices):
|
||||
for index, (option_value, option_label) in enumerate(chain(self.choices)):
|
||||
if option_value is None:
|
||||
option_value = ''
|
||||
|
||||
subgroup = []
|
||||
if isinstance(option_label, (list, tuple)):
|
||||
index = groups[-1][2] + 1
|
||||
group_name = option_value
|
||||
subindex = 0
|
||||
subgroup = []
|
||||
groups.append((option_value, subgroup, index))
|
||||
choices = option_label
|
||||
else:
|
||||
index = len(default[1])
|
||||
subgroup = default[1]
|
||||
group_name = None
|
||||
subindex = None
|
||||
choices = [(option_value, option_label)]
|
||||
groups.append((group_name, subgroup, index))
|
||||
|
||||
for subvalue, sublabel in choices:
|
||||
selected = (
|
||||
|
||||
Reference in New Issue
Block a user