2

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?

2
  • Just do language = models.CharField(max_length=20, choices=LANGUAGE, required = True) Commented Jan 28, 2017 at 17:27
  • widget overrides that required attribute Commented Jan 29, 2017 at 0:48

1 Answer 1

1

I simply changed it to the following:

'language': forms.RadioSelect(attrs={'required': True}),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.