-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
fixed SelectMultipleField none_of validator #538
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -594,10 +594,20 @@ def __init__(self, values, message=None, values_formatter=None): | |
self.values_formatter = values_formatter | ||
|
||
def __call__(self, form, field): | ||
if field.type == "SelectMultipleField": | ||
if any(e in self.values for e in field.data): | ||
message = self.message | ||
if message is None: | ||
message = field.gettext('Invalid value, cannot be any of: %(values)s.') | ||
|
||
raise ValidationError( | ||
message % dict(values=self.values_formatter(self.values)) | ||
) | ||
|
||
if field.data in self.values: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the field is |
||
message = self.message | ||
if message is None: | ||
message = field.gettext("Invalid value, can't be any of: %(values)s.") | ||
message = field.gettext("Invalid value, cannot be any of: %(values)s.") | ||
|
||
raise ValidationError( | ||
message % dict(values=self.values_formatter(self.values)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be the solution, as it excludes any other fields that have a list of data. And it just doesn't feel very good to check the name of a specific field like this.
Could maybe do
if isinstance(field.data, list)
. That might have issues withFieldList
, but that might not matter. Would also have issues if you want to check "none of these specific sets of choices", rather than "doesn't contain any of these choices".