Question

I'm trying to add an attribute to my form field email using crispy forms

This is what I have

 def __init__(self, *args, **kwargs):
        super(RedeemForm, self).__init__(*args, **kwargs)
        setup_bootstrap_helpers(self)
        self.helper.layout = Layout(
            Fieldset(
                '',
                Div(
                    Div(
                        Field('mobile', css_class="form-control", title="test"),
                        css_class="col-xs-8",
                    ),
                    css_class="row",
                ),

                Div(
                    Div(
                        Field('email', css_class="form-control", title="test"),
                        css_class="col-xs-8",
                    ),
                    css_class="row",
                ),


            ),

        )


 mobile = forms.EmailField(max_length=100, required=True)
 email = forms.CharField(max_length=100, required=True)

I would like to add required i.e.

 <input type="email" required />

I cannot see how to achieve this using crispy forms.

Was it helpful?

Solution

class RedeemForm(forms.ModelForm):
    email = forms.CharField(required=True)

    def __init__(self, *args, **kwargs):
        super(RedeemForm, self).__init__(*args, **kwargs)
        setup_bootstrap_helpers(self)
        .....................

or

        def __init__(self, *args, **kwargs):
            super(RedeemForm, self).__init__(*args, **kwargs)
            setup_bootstrap_helpers(self)
            .....................
            self.fields['email'].required = True
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top