diff options
| author | Tim Graham <timograham@gmail.com> | 2017-05-03 07:21:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-03 07:21:44 -0400 |
| commit | d302e2c09c281e6b1e187f704f656e5e79e69246 (patch) | |
| tree | b48c0e196175ae368268b5605a29ad79c99764f0 /django/forms | |
| parent | 13cd5b067054f40c6ca723c97fff56c510c04295 (diff) | |
Fixed #28157 -- Fixed choice ordering in form fields with grouped and non-grouped options.
Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/widgets.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 2feded85c7..37c11f1241 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -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 = ( |
