Reputation: 1759
I have looked over this documentation (http://streamhacker.com/2010/03/08/jquery-validation-django-forms/) for some help regarding form validation. In my forms.py I have the following:
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = ['first_name', 'last_name', 'language']
widgets = {
'language': forms.RadioSelect(attrs={
'class':'{required:true}'
}),
}
So for the language field, I want to serve it as a RadioButton
field and I want to make it a required field. So if the user leaves this field empty, then a warning would pop up. Here is my models.py where I defined the language
column:
LANGUAGE = (('AR', 'Arabic'), ('FR', 'French'), ('ES', 'Spanish'))
language = models.CharField(max_length=20, choices=LANGUAGE)
Anyways, no warnings pop up when I submit the form even with the language
field empty. Any ideas?
Upvotes: 2
Views: 459
Reputation: 1759
I simply changed it to the following:
'language': forms.RadioSelect(attrs={'required': True}),
Upvotes: 1