django-orchestra/orchestra/forms/fields.py

16 lines
514 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django import forms
class MultiSelectFormField(forms.MultipleChoiceField):
""" http://djangosnippets.org/snippets/1200/ """
widget = forms.CheckboxSelectMultiple
def __init__(self, *args, **kwargs):
self.max_choices = kwargs.pop('max_choices', 0)
super(MultiSelectFormField, self).__init__(*args, **kwargs)
def clean(self, value):
if not value and self.required:
raise forms.ValidationError(self.error_messages['required'])
return value