Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a data_help method in Form #26332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c8914f5
Add a data_help method in Form
Feb 27, 2018
1b89f9d
Add a template fot div_layout
Feb 27, 2018
8b97c1b
Use a shortcut to acces help var in Twig template
Feb 27, 2018
e311838
Remove raw filter for help
Feb 27, 2018
831693a
Add trans filter
Feb 27, 2018
2c2c045
Adapt existant tests
Feb 27, 2018
d3e3e49
Fix: check translation domain
Feb 27, 2018
067c681
Template for table, Foundation and Bootstrap 3
Feb 28, 2018
8094804
Add Tests
Feb 28, 2018
c934e49
Add test without help set
Feb 28, 2018
f15bc79
Fix coding standards
Feb 28, 2018
4f2581d
Use array long syntax
Feb 28, 2018
ba798df
FrameworkBundle Tests
Feb 28, 2018
6ea7a20
Remove vars option from form_help
Feb 28, 2018
058489d
Add an id to the help
Mar 1, 2018
1f3a15e
Rename id
Mar 1, 2018
bf4d08c
Add aria-describedBy on input
Mar 1, 2018
30deaa9
PSR fix
Mar 1, 2018
77fa317
Fix Test
Mar 1, 2018
f948147
Rename help id (snake_case)
Mar 1, 2018
aada72c
Set help option on nul as default
Mar 1, 2018
edb95f8
Use array long syntax
Mar 1, 2018
98065d3
fabpot.io fix
Mar 1, 2018
fd53bc5
Enable aria-described in row for all Templates
Mar 1, 2018
69ded67
Added form_help on horizontal design and removed special variable
Nyholm Mar 18, 2018
f1d13a8
Fix Fabpot.io
mpiot Mar 20, 2018
075fcfd
[FrameworkBundle] Add widgetAtt to formTable/form_row
mpiot Mar 20, 2018
d84be70
Update composer files
mpiot Mar 21, 2018
437b77e
Skip renderHelp test as skipped if not override
mpiot Mar 21, 2018
32bf1f6
Test the renderHelp method in all Tests about help to skip them if ne…
mpiot Mar 21, 2018
8b937ff
Try without try/catch
mpiot Mar 21, 2018
c74e0dc
Use spaceless balises in Twig templates
mpiot Mar 22, 2018
d723756
Fix some mistakes
mpiot Mar 23, 2018
859ee03
Revert: remove comment line from twig templates
mpiot Mar 23, 2018
585ca28
Add return type hint
mpiot Mar 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add aria-describedBy on input
  • Loading branch information
Mathieu Piot authored and mpiot committed Mar 23, 2018
commit bf4d08c5aefed7bc15ab76cac0434f5790b90e57
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
<div>
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, { 'helpBlockDisplayed': true }) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we check if help is not empty here?
That would make the logic in widget_attributes simpler

Copy link
Contributor Author

@mpiot mpiot Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is when a user just display form_widget for exemple, the form_help is not call, then we don't have to display the aria-describedBy, because the block doesn't exists.

That's why I do the test later, else, user say if he declare the form_help to do the link between help block and input.

In the row, I do it automatically, because I'm sure the help block is displayed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Could we try something like:

{{- form_widget(form, { 'helpBlockDisplayed': (help is not empty) }) -}} or that may be a syntax error.

Copy link
Contributor Author

@mpiot mpiot Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same problem, we can't do it automatically, the help may be set, but don't displayed if the user do:

{{ form_label(form.name) }}
{{ form_errors(form.name) }}
{{ form_widget(form.name) }}

He doesn't call form_label, then help is not displayed, but set in the form.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, But it that a problem?

If the user do:

{{ form_label(form.name) }}
{{ form_errors(form.name) }}
{{ form_widget(form.name) }}

Then no form help will be rendered and no aria-describedBy will be used.


If the user do:

{{ form_label(form.name) }}
{{ form_errors(form.name) }}
{{ form_widget(form.name) }}
{{ form_help(form.name) }}

Then form help will be rendered but no aria-describedBy will be used.


We should only make sure that the logic is clean and when the user do:

{{ form_row(form.name) }}

Then form help will be rendered AND aria-describedBy will be used.

Copy link
Contributor Author

@mpiot mpiot Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do that, I've do it to permit the user to add the aria-describedBy when don't use form_row. Then, I'm not really sure it's the best way to do, the method must work for all.

{{- form_help(form) -}}
</div>
{%- endblock form_row -%}
Expand Down Expand Up @@ -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 -%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace and helpBlockDisplayed and with and helpBlockDisplayed same as(true) and

{{ block('attributes') }}
{%- endblock widget_attributes -%}

Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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 ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& $helpBlockDisplayed && => && true === $helpBlockDisplayed &&

<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
56 changes: 56 additions & 0 deletions 56 src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,62 @@ public function testHelpNotSet()
$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');
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.