Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Required Attribute From Django Form

I want to remove required attribute from HTML Form. And it should give error from server side that this field is required. Previously i was using required self.fields['group_name'].required=False. But it is not giving error for blank or null data. Then i came to know use_required_attribute, but i don't know about it and how to use it.

class GroupForm(forms.ModelForm):
    use_required_attribute = False
    class Meta:
        model = Groups
        fields = ['group_name', 'group_description', 'group_status']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
like image 657
Cipher Avatar asked Feb 08 '19 07:02

Cipher


1 Answers

Use form = GroupForm(use_required_attribute=False) when you initialize your form in your views.py.

like image 178
anupsabraham Avatar answered Nov 15 '22 08:11

anupsabraham