Add aria-describedBy on input

This commit is contained in:
Mathieu Piot 2018-03-01 08:06:19 +01:00 committed by Mathieu Piot
parent 1f3a15e33b
commit bf4d08c5ae
4 changed files with 62 additions and 4 deletions

View File

@ -309,7 +309,7 @@
<div>
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, { 'helpBlockDisplayed': true }) -}}
{{- form_help(form) -}}
</div>
{%- endblock form_row -%}
@ -397,6 +397,7 @@
id="{{ id }}" name="{{ full_name }}"
{%- if disabled %} disabled="disabled"{% endif -%}
{%- if required %} required="required"{% endif -%}
{%- if helpBlockDisplayed is defined and helpBlockDisplayed and help is not empty %} aria-describedby="{{ id }}HelpBlock"{% endif -%}
{{ block('attributes') }}
{%- endblock widget_attributes -%}

View File

@ -1,6 +1,6 @@
<div>
<?php echo $view['form']->label($form) ?>
<?php echo $view['form']->errors($form) ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->help($form); ?>
<?php echo $view['form']->widget($form, array('helpBlockDisplayed' => true)) ?>
<?php echo $view['form']->help($form) ?>
</div>

View File

@ -1,3 +1,4 @@
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
<?php if ($required): ?> required="required"<?php endif ?>
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
<?php if (isset($helpBlockDisplayed) && $helpBlockDisplayed && !empty($help)): ?> aria-describedby="<?php echo $view->escape($id) ?>HelpBlock"<?php endif ?>
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>

View File

@ -436,6 +436,62 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
$this->assertMatchesXpath($html, '');
}
public function testHelpSetLinkFromWidget()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
'help' => 'Help text test!',
));
$view = $form->createView();
$html = $this->renderWidget($view, array('helpBlockDisplayed' => true));
$this->assertMatchesXpath($html,
'/input
[@aria-describedby="nameHelpBlock"]
'
);
}
public function testHelpSetNotLinkedFromWidget()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
'help' => 'Help text test!',
));
$view = $form->createView();
$html = $this->renderWidget($view);
$this->assertMatchesXpath($html,
'/input
[not(@aria-describedby)]
'
);
}
public function testHelpNotSetLinkFromWidget()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$view = $form->createView();
$html = $this->renderWidget($view, array('helpBlockDisplayed' => true));
$this->assertMatchesXpath($html,
'/input
[not(@aria-describedby)]
'
);
}
public function testHelpNotSetNotLinkedFromWidget()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$view = $form->createView();
$html = $this->renderWidget($view);
$this->assertMatchesXpath($html,
'/input
[not(@aria-describedby)]
'
);
}
public function testErrors()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');