Your solution works!!! Thanks a lot!!!

On Friday, September 5, 2014 10:27:30 PM UTC+4, Collin Anderson wrote:
>
> I'd recommend not using a custom field for this. Instead, you can do 
> something like:
>
> class ExerciseForm(forms.Form):
>         exercise_field = forms.CharField(widget=forms.TextInput(attrs={
> 'autocomplete': 'off', 'autofocus': 'autofocus'}))
>
>         def __init__(self, *args, **kwargs):
>             self.language = kwargs.pop('language', None)
>             self.dictionary = kwargs.pop('dictionary', None)
>             self.exercise_text = self.getRandomText(self.language, self.
> dictionary)
>             super(ExerciseForm, self).__init__(*args, **kwargs)
>
>         def clean_exercise_field(self):
>             if self.cleaned_data['exercise_field'] != self.exercise_text:
>                 raise forms.ValidationError("Texts don't match")
>             return self.cleaned_data['exercise_field']
>
>
> https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/807783db-548a-4cee-b083-5fa5dea5f783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to