jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

Update widget.is_required value on field.required update #166

Closed kalekseev closed 8 years ago

kalekseev commented 8 years ago

I didn't found in documentation why required attr is still rendered when I change field.required to False. So I looked into the code and found that I have to update widget.is_required too. This change keeps field.required and widget.is_required in sync. I'm not sure that this is a good solution for everyone and of course it will break others people projects but at least we can add information about widget.is_required to the documentation.

gregmuellegger commented 8 years ago

Hi. This behaviour is inherited from Django. The is_required on the widget is set here: https://github.com/django/django/blob/master/django/forms/fields.py#L103 So, if you change field.required after you instantiated the field, you have to update widget.is_required yourself.

This might not be the best API for a developer to use, but that's the way Django implements it and django-floppyforms tries to emulate this behaviour where-ever possible so that it can work as a drop-in replacement. So I won't include this PR into floppyforms, but I hope that the link above to the Django code might help you to resolve the issue you have.

Thanks for the efforts you put into this! Keep contributing :)