Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backported #598 #639

Merged
merged 2 commits into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,13 @@
.. currentmodule:: wtforms


Unreleased
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "Version 2.3.2", with "Unreleased" under it. Can fix that when you make the release PR.

----------

- Fixed a bug with :class:`~fields.SelectField` choices shortcut at
form submission. :pr:`598, 639`


Version 2.3.1
-------------

Expand Down
7 changes: 7 additions & 0 deletions tests/fields.py
Expand Up @@ -342,6 +342,13 @@ def test_choice_shortcut(self):
form = F(a="bar")
self.assertEqual(form.a(), """<select id="a" name="a"><option value="foo">foo</option><option selected value="bar">bar</option></select>""")

def test_choice_shortcut_post(self):
F = make_form(a=SelectField(choices=["foo", "bar"]))
form = F(DummyPostData(a=["foo"]))
assert form.validate()
assert form.a.data == "foo"
assert len(form.a.errors) == 0

def test_empty_choice(self):
F = make_form(a=SelectField(choices=[], validate_choice=False))
form = F(a="bar")
Expand Down
4 changes: 2 additions & 2 deletions wtforms/fields/core.py
Expand Up @@ -506,8 +506,8 @@ def process_formdata(self, valuelist):

def pre_validate(self, form):
if self.validate_choice:
for v, _ in self.choices:
if self.data == v:
for _, _, match in self.iter_choices():
if match:
break
else:
raise ValueError(self.gettext("Not a valid choice"))
Expand Down