Closed kalekseev closed 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 :)
I didn't found in documentation why
required
attr is still rendered when I changefield.required
to False. So I looked into the code and found that I have to updatewidget.is_required
too. This change keepsfield.required
andwidget.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 aboutwidget.is_required
to the documentation.