Open dylanmccall opened 8 years ago
Hm, I think I see the problem here. We have a server-side behaviour in the form (allow either all fields to be empty, unless at least one field is filled in, then require all to be filled in) that we cannot replicate with a html-only solution.
I would recommend adding the novalidate attribute to your <form>
tag as described here: http://django-floppyforms.readthedocs.org/en/latest/differences.html#client-side-validation
But I know that this does not replicate the behaviour you expect. What would you suggest as a solution? Remove the <input required>
attributes when empty_permitted=True
?
I am using Floppyforms in an elaborate form page consisting of several nested ModelForm objects, and some form sets. Some of these form sets have min_num=0, which causes the initial forms to be created with
empty_permitted = True
. That is, the server-side validation won't complain if the entire form is empty. Required fields are only enforced if the form has been modified. However, even for those forms, any fields marked as required are given the HTML5 required attribute, making it impossible to submit the form without filling them in.Steps to reproduce:
And a simple code example:
Expected output:
Actual output:
Workaround
Here's a workaround I have been using. A complete solution also needs some JavaScript code that interprets data-was-required and does fun things:
This goes through every field in the form, and if the widget has been marked as required we make sure to strip the required attribute, set
is_required = False
(so it isn't passed to the widget's template), and then add our own attribute to keep track of this field's more complex validation rules.