Forms (and formsets) don't always generate valid HTML for hidden fields
|Reported by:||mtredinnick||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Creating a form with only hidden fields and than calling as_p() on it generates invalid (X)HTML. The input elements must reside inside certain block-level elements and this doesn't always happen. In r9067 I made a change that made this work when displaying error messages for such fields, but the general case is trickier.
The problem is that we can't just apply the same change as r9067 because that would introduce, for example, an empty table row in the as_table() method. This normally wouldn't be an issue (why, exactly, are you calling as_p() on a form that doesn't display anything?), but it arises fairly naturally with formsets. The management form for formsets is a form that only contains hidden fields. Thus, any formset display is slightly invalid. Fixing this doesn't appear to be entirely trivial, so I didn't drop in any kind of patch around the time of r9067.
There are some tests in regressiontests/forms/forms.py that actually demonstrate the problem here: except they consider the invalid output to be valid. So any patch fixing this will cause a couple of tests for hidden fields to "fail" and the tests will need to be fixed.
Change History (6)
comment:1 Changed 7 years ago by jacob
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted