Last active
March 2, 2021 17:04
-
-
Save rafaelcanovas/6116630 to your computer and use it in GitHub Desktop.
Monkey-patching HTML5 required attribute for Django forms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
class HTML5Form(forms.Form): | |
def __init__(self, *args, **kwargs): | |
super(MyForm, self).__init__(*args, **kwargs) | |
for _, field in self.fields.items(): | |
if field.widget.is_required: | |
field.widget.attrs['required'] = 'required' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment