Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Force validation in pre_validate #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions wtforms_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from wtforms import widgets
from wtforms.compat import text_type, string_types
from wtforms.fields import SelectFieldBase
from wtforms.validators import ValidationError
from wtforms.validators import ValidationError, StopValidation

try:
from sqlalchemy.orm.util import identity_key
Expand Down Expand Up @@ -177,8 +177,9 @@ def process_formdata(self, valuelist):
self._formdata = set(valuelist)

def pre_validate(self, form):
data = self.data # need to run _get_data
if self._invalid_formdata:
raise ValidationError(self.gettext('Not a valid choice'))
raise StopValidation(self.gettext('Not a valid choice'))
elif self.data:
obj_list = list(x[1] for x in self._get_object_list())
for v in self.data:
Expand Down