Skip to content

Commit

Permalink
Support WTForms 3.1 iter_choices 4 item return values
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhwilliams authored and cjmayo committed Aug 3, 2024
1 parent be57df2 commit e8449f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions flask_admin/contrib/sqla/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class CheckboxListInput:

def __call__(self, field, **kwargs):
items = []
for val, label, selected in field.iter_choices():
for field_choices in field.iter_choices():
if len(field_choices) == 3: # wtforms <3.1, >=3.1.1, <3.2
value, label, selected = field_choices
else:
value, label, selected, _ = field_choices
args = {
'id': val,
'id': value,
'name': field.name,
'label': escape(label),
'selected': ' checked' if selected else '',
Expand Down
6 changes: 5 additions & 1 deletion flask_admin/model/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ def get_kwargs(self, field, kwargs):

choices = []
selected_ids = []
for value, label, selected in field.iter_choices():
for field_choices in field.iter_choices():
if len(field_choices) == 3: # wtforms <3.1, >=3.1.1, <3.2
value, label, selected = field_choices
else:
value, label, selected, _ = field_choices
try:
label = text_type(label)
except TypeError:
Expand Down

0 comments on commit e8449f5

Please sign in to comment.