On Sun, Jul 12, 2009 at 12:35 PM, Lokesh <lokeshmarema...@gmail.com> wrote:

>
> Hi,
>
> forms.py
> education = forms.MultipleChoiceField(choices=education_filler
> (education_list))
>
> In one of my forms I have the field to select multiple options for
> education. I am able to populate all the choices and also multi
> selection. But from the above code I would like to restrict the user
> to select upto 3 choices and not more than that.
>
> Could some one guide me on how to restrict the user to select the max
> limit of choices or set the maximum limit while defining the field.
>
> Thanks in advance.
>
> Regards,
> Lokesh
> >
>
You could write a clean_education method on the form as documented here:
http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation

It might look something like:

def clean_education(self):
    value = self.cleaned_data['education']
    if len(value) > 3:
        raise forms.ValidationError("You can't select more than 3 items.")
    return value

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you want"
-- Me

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to