form: add aria-required to widgets (#8676)

This commit is contained in:
Frédéric Péters 2015-10-17 19:22:29 +02:00
parent 05f8268ae2
commit 7088b86772
1 changed files with 10 additions and 0 deletions

View File

@ -153,6 +153,8 @@ Widget.is_prefilled = is_prefilled
def string_render_content(self):
attrs = {'id': 'form_' + self.name}
if self.required:
attrs['aria-required'] = 'true'
if self.attrs:
attrs.update(self.attrs)
return htmltag("input", xml_end=True, type=self.HTML_TYPE, name=self.name,
@ -162,6 +164,8 @@ StringWidget.render_content = string_render_content
def file_render_content(self):
attrs = {'id': 'form_' + str(self.name).split('$')[0]}
if self.required:
attrs['aria-required'] = 'true'
if self.attrs:
attrs.update(self.attrs)
return htmltag("input", xml_end=True, type=self.HTML_TYPE, name=self.name,
@ -171,6 +175,8 @@ FileWidget.render_content = file_render_content
def text_render_content(self):
attrs = {'id': 'form_' + self.name}
if self.required:
attrs['aria-required'] = 'true'
if self.attrs:
attrs.update(self.attrs)
return (htmltag("textarea", name=self.name, **attrs) +
@ -205,6 +211,8 @@ RadiobuttonsWidget.render_content = radiobuttons_render_content
def checkbox_render_content(self):
attrs = {'id': 'form_' + self.name}
if self.required:
attrs['aria-required'] = 'true'
if self.attrs:
attrs.update(self.attrs)
return htmltag("input", xml_end=True, type="checkbox", name=self.name,
@ -215,6 +223,8 @@ CheckboxWidget.render_content = checkbox_render_content
def select_render_content(self):
attrs = {'id': 'form_' + self.name}
if self.required:
attrs['aria-required'] = 'true'
if self.attrs:
attrs.update(self.attrs)
tags = [htmltag("select", name=self.name, **attrs)]