2022-01-13 23:08:38 +00:00
|
|
|
from django.forms import CharField, Form, HiddenInput
|
2015-08-31 02:13:42 +00:00
|
|
|
|
|
|
|
from .base import WidgetTest
|
|
|
|
|
|
|
|
|
|
|
|
class HiddenInputTest(WidgetTest):
|
|
|
|
widget = HiddenInput()
|
|
|
|
|
|
|
|
def test_render(self):
|
2018-01-21 07:09:10 +00:00
|
|
|
self.check_html(
|
|
|
|
self.widget, "email", "", html='<input type="hidden" name="email">'
|
|
|
|
)
|
2016-08-12 17:59:01 +00:00
|
|
|
|
|
|
|
def test_use_required_attribute(self):
|
|
|
|
# Always False to avoid browser validation on inputs hidden from the
|
|
|
|
# user.
|
|
|
|
self.assertIs(self.widget.use_required_attribute(None), False)
|
|
|
|
self.assertIs(self.widget.use_required_attribute(""), False)
|
|
|
|
self.assertIs(self.widget.use_required_attribute("foo"), False)
|
2022-01-13 23:08:38 +00:00
|
|
|
|
|
|
|
def test_fieldset(self):
|
|
|
|
class TestForm(Form):
|
|
|
|
template_name = "forms_tests/use_fieldset.html"
|
|
|
|
field = CharField(widget=self.widget)
|
|
|
|
|
|
|
|
form = TestForm()
|
|
|
|
self.assertIs(self.widget.use_fieldset, False)
|
|
|
|
self.assertHTMLEqual(
|
|
|
|
'<input type="hidden" name="field" id="id_field">',
|
|
|
|
form.render(),
|
|
|
|
)
|