Skip to content

SelectMultipleField does not implement validate_choice parameter #606

@KittyKittyKitKat

Description

@KittyKittyKitKat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions