mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #32339 -- Added use_fieldset to Widget.
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from django.forms import (
|
||||
CharField,
|
||||
FileInput,
|
||||
Form,
|
||||
MultipleChoiceField,
|
||||
MultiValueField,
|
||||
MultiWidget,
|
||||
@@ -51,7 +52,9 @@ class ComplexField(MultiValueField):
|
||||
MultipleChoiceField(choices=WidgetTest.beatles),
|
||||
SplitDateTimeField(),
|
||||
)
|
||||
super().__init__(fields, required, widget, label, initial)
|
||||
super().__init__(
|
||||
fields, required=required, widget=widget, label=label, initial=initial
|
||||
)
|
||||
|
||||
def compress(self, data_list):
|
||||
if data_list:
|
||||
@@ -296,3 +299,22 @@ class MultiWidgetTest(WidgetTest):
|
||||
# w2 ought to be independent of w1, since MultiWidget ought
|
||||
# to make a copy of its sub-widgets when it is copied.
|
||||
self.assertEqual(w1.choices, [1, 2, 3])
|
||||
|
||||
def test_fieldset(self):
|
||||
class TestForm(Form):
|
||||
template_name = "forms_tests/use_fieldset.html"
|
||||
field = ComplexField(widget=ComplexMultiWidget)
|
||||
|
||||
form = TestForm()
|
||||
self.assertIs(form["field"].field.widget.use_fieldset, True)
|
||||
self.assertHTMLEqual(
|
||||
"<div><fieldset><legend>Field:</legend>"
|
||||
'<input type="text" name="field_0" required id="id_field_0">'
|
||||
'<select name="field_1" required id="id_field_1" multiple>'
|
||||
'<option value="J">John</option><option value="P">Paul</option>'
|
||||
'<option value="G">George</option><option value="R">Ringo</option></select>'
|
||||
'<input type="text" name="field_2_0" required id="id_field_2_0">'
|
||||
'<input type="text" name="field_2_1" required id="id_field_2_1">'
|
||||
"</fieldset></div>",
|
||||
form.render(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user