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

SelectMultipleField does not implement validate_choice parameter #606

Closed
KittyKittyKitKat opened this issue May 19, 2020 · 1 comment
Closed
Labels
bug Unexpected behavior

Comments

@KittyKittyKitKat
Copy link

KittyKittyKitKat commented May 19, 2020

Actual Behavior

>>> import wtforms
>>> class F(wtforms.Form):
...     single = wtforms.SelectField(choices=[], validate_choice=False)
...     multiple = wtforms.SelectMultipleField(choices=[], validate_choice=False)
>>> f = F()
>>> f.single.process_data(1)
>>> f.multiple.process_data([1])
>>> f.validate()
False
>>> f.single.errors
[]
>>> f.multiple.errors
["'1' is not a valid choice for this field"]

Expected Behavior

>>> import wtforms
>>> class F(wtforms.Form):
...     single = wtforms.SelectField(choices=[], validate_choice=False)
...     multiple = wtforms.SelectMultipleField(choices=[], validate_choice=False)
>>> f = F()
>>> f.single.process_data(1)
>>> f.multiple.process_data([1])
>>> f.validate()
True
>>> f.single.errors
[]
>>> f.multiple.errors
[]

The pre_validate function in the SelectMultipleField class overwrites the functionality for validate_choice present in the pre_validate function of its parent class, SelectField. Thus, the validate_choice parameter in SelectMultipleField is completely disregarded when the form's validate function is called, resulting in a wrongful validation error.
I believe this functionality should be implemented in order to add additional functionality consistency to the API.

Environment

  • Python version: 3.7.6
  • wtforms version: 2.3.1
@KittyKittyKitKat KittyKittyKitKat changed the title SelectMultipleField does not implement validate_choice SelectMultipleField does not implement validate_choice parameter May 19, 2020
@azmeuk azmeuk added the bug Unexpected behavior label May 20, 2020
@azmeuk
Copy link
Member

azmeuk commented May 20, 2020

Hi. Thank you for your bug report.
As you have a pretty good insight on how to fix this issue, would you consider submitting a patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior
Development

No branches or pull requests

2 participants