mirror of https://github.com/django/django.git
Fixed #12437 -- Added css_classes to Form._html_output()
This commit is contained in:
parent
c2b4967e76
commit
1884bf8e8e
|
@ -227,6 +227,7 @@ class BaseForm(object):
|
|||
'field': six.text_type(bf),
|
||||
'help_text': help_text,
|
||||
'html_class_attr': html_class_attr,
|
||||
'css_classes': css_classes,
|
||||
'field_name': bf.html_name,
|
||||
})
|
||||
|
||||
|
@ -250,6 +251,7 @@ class BaseForm(object):
|
|||
'field': '',
|
||||
'help_text': '',
|
||||
'html_class_attr': html_class_attr,
|
||||
'css_classes': '',
|
||||
'field_name': '',
|
||||
})
|
||||
output.append(last_row)
|
||||
|
|
|
@ -2274,11 +2274,57 @@ class FormsTestCase(SimpleTestCase):
|
|||
some_field = CharField()
|
||||
|
||||
def as_p(self):
|
||||
return self._html_output('<p id="p_%(field_name)s"></p>', '%s', '</p>', ' %s', True)
|
||||
return self._html_output(
|
||||
normal_row='<p id="p_%(field_name)s"></p>',
|
||||
error_row='%s',
|
||||
row_ender='</p>',
|
||||
help_text_html=' %s',
|
||||
errors_on_separate_row=True,
|
||||
)
|
||||
|
||||
form = SomeForm()
|
||||
self.assertHTMLEqual(form.as_p(), '<p id="p_some_field"></p>')
|
||||
|
||||
def test_field_without_css_classes(self):
|
||||
"""
|
||||
`css_classes` may be used as a key in _html_output() (empty classes).
|
||||
"""
|
||||
class SomeForm(Form):
|
||||
some_field = CharField()
|
||||
|
||||
def as_p(self):
|
||||
return self._html_output(
|
||||
normal_row='<p class="%(css_classes)s"></p>',
|
||||
error_row='%s',
|
||||
row_ender='</p>',
|
||||
help_text_html=' %s',
|
||||
errors_on_separate_row=True,
|
||||
)
|
||||
|
||||
form = SomeForm()
|
||||
self.assertHTMLEqual(form.as_p(), '<p class=""></p>')
|
||||
|
||||
def test_field_with_css_class(self):
|
||||
"""
|
||||
`css_classes` may be used as a key in _html_output() (class comes
|
||||
from required_css_class in this case).
|
||||
"""
|
||||
class SomeForm(Form):
|
||||
some_field = CharField()
|
||||
required_css_class = 'foo'
|
||||
|
||||
def as_p(self):
|
||||
return self._html_output(
|
||||
normal_row='<p class="%(css_classes)s"></p>',
|
||||
error_row='%s',
|
||||
row_ender='</p>',
|
||||
help_text_html=' %s',
|
||||
errors_on_separate_row=True,
|
||||
)
|
||||
|
||||
form = SomeForm()
|
||||
self.assertHTMLEqual(form.as_p(), '<p class="foo"></p>')
|
||||
|
||||
def test_field_name_with_hidden_input(self):
|
||||
"""
|
||||
BaseForm._html_output() should merge all the hidden input fields and
|
||||
|
|
Loading…
Reference in New Issue