Skip to content

Allow form field with required=False #264

Answered by AltusBarry
un1t asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @un1t, we are sorry to hear you are having issues upgrading the django-recaptcha package.

Unfortunately, we do not foresee allowing a required toggle on the field.
Adding a recaptcha field means one wants to protect a specific aspect of your site against abuse.
Wanting to make it optional must be a deliberate implementation change, not a mere toggle.

The simplest way would be to just remove the captcha from the form's error list:

class Form(forms.Form):
    captcha = RecaptchaField()

    def clean(self, *args, **kwargs):
        cleaned_data = super(Form, self).clean(*args, **kwargs)
        if not user.needs_captcha and "captcha" in self.errors.keys():
            return True
    …

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by thibaudcolas
Comment options

You must be logged in to vote
1 reply
@HeartthrobRob
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #186 on January 26, 2022 22:10.