Permalink
Browse files

Fixed validation and rendering of MultipleSelectField. Thanks Ali Afs…

…har <aafshar@gmail.com>
  • Loading branch information...
james
james committed Jul 25, 2008
1 parent 37386c2 commit fdcda3f9125a8d2f1064c0ffe6a6fa6d0c46b6b5
Showing with 10 additions and 2 deletions.
  1. +10 −2 wtforms/fields.py
View
@@ -119,13 +119,21 @@ def _validate(self, *args):
class SelectMultipleField(SelectField):
def __call__(self, **kwargs):
- super(SelectMultipleField, self).__call__(multiple="multiple", **kwargs)
+ return super(SelectMultipleField, self).__call__(multiple="multiple", **kwargs)
def _selected(self, value):
- return (self.checker(value) in self.data)
+ if self.data is not None:
+ return (self.checker(value) in self.data)
def process_formdata(self, valuelist):
self.data = [self.checker(x) for x in valuelist]
+
+ def _validate(self, *args):
+ choices = [c[0] for c in self.choices]
+ for d in self.data:
+ if d not in choices:
+ raise ValidationError("'%s' is not a valid choice for this field" % d)
+
class TextField(Field):
def __call__(self, **kwargs):

0 comments on commit fdcda3f

Please sign in to comment.