We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
>>> class DummyPostData(dict): ... def getlist(self, key): ... v = self[key] ... if not isinstance(v, (list, tuple)): ... v = [v] ... return v ... >>> import wtforms >>> class F(wtforms.Form): ... foo=wtforms.SelectMultipleField(choices=[('1', 'One'), ('2', 'Two')], coerce=int) ... >>> post_data = DummyPostData(foo=["1", "2"]) >>> form = F(post_data) >>> form.validate() False >>> form.errors {'foo': ["'1', '2' are not valid choices for this field."]}
The form should be valid when the post data is a valid option after coercing both post data and choices:
>>> class DummyPostData(dict): ... def getlist(self, key): ... v = self[key] ... if not isinstance(v, (list, tuple)): ... v = [v] ... return v ... >>> import wtforms >>> class F(wtforms.Form): ... foo=wtforms.SelectMultipleField(choices=[('1', 'One'), ('2', 'Two')], coerce=int) ... >>> post_data = DummyPostData(foo=["1", "2"]) >>> form = F(post_data) >>> form.validate() True
The text was updated successfully, but these errors were encountered:
There is indeed a difference of behavior between SelectField and SelectMultipleField.
SelectField
SelectMultipleField
>>> import wtforms >>> from werkzeug.datastructures import ImmutableMultiDict >>> class F(wtforms.Form): ... foo=wtforms.SelectMultipleField(choices=[('1', 'One'), ('2', 'Two')], coerce=int) ... bar=wtforms.SelectField(choices=[('1', 'One'), ('2', 'Two')], coerce=int) >>> form = F(ImmutableMultiDict({"foo": ["1"], "bar": ["1"]})) >>> form.validate() False >>> form.errors {'foo': ["'1' is not a valid choice for this field."]}
Sorry, something went wrong.
Fixed in version 3.1.2
Successfully merging a pull request may close this issue.
Actual Behavior
Expected Behavior
The form should be valid when the post data is a valid option after coercing both post data and choices:
Environment
The text was updated successfully, but these errors were encountered: