-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make it possible to add extra form_row container attributes #6547
Make it possible to add extra form_row container attributes #6547
Conversation
This is a nice addition, but what about integrate Symfony row_attr? |
205f406
to
f0691b5
Compare
I think we can achieve the same adapting (adding the id) row_attr and there is no need for an extra option. |
bbbeb65
to
481ee6a
Compare
Nice, I have implemented the row_attr |
Nice! EDIT: Forget about the thing of tests that do not pass and the submit call, I've created #6627 to fix it.
SonataAdminBundle/tests/Form/AdminLayoutTestCase.php Lines 30 to 39 in 78b1db8
public function testRowWithErrors(): void
{
$form = $this->factory->createNamed('name', TextType::class);
$form->addError(new FormError('[trans]Error 1[/trans]'));
$form->addError(new FormError('[trans]Error 2[/trans]'));
$form->submit([]);
$view = $form->createView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html, '/div[@class="form-group has-error"][@id="sonata-ba-field-container-name"]');
} And also can you please add a test for this? I tried (feel free to used it or make another one): public function testRowAttr(): void
{
$form = $this->factory->createNamed('name', TextType::class, '', [
'row_attr' => [
'class' => 'foo',
'data-value' => 'bar',
]
]);
$view = $form->createView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html, '//div[@class="foo form-group"][@data-value="bar"][@id="sonata-ba-field-container-name"]');
} |
#6627 is merged, please rebase |
@@ -357,7 +357,7 @@ file that was distributed with this source code. | |||
|
|||
{% block form_row %} | |||
{% set show_label = show_label ?? true %} | |||
<div class="form-group{% if errors|length > 0 %} has-error{% endif %}" id="sonata-ba-field-container-{{ id }}"> | |||
<div{% with {attr: row_attr|merge({id: 'sonata-ba-field-container-'~id, class: (row_attr.class|default('') ~ ' form-group' ~ ((not compound or force_error|default(false)) and not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is hard to read. Please wrap some parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this line in some variables
e148e41
to
8d484bd
Compare
Nice test, I have used it |
36c5412
to
be1b0f2
Compare
be1b0f2
to
72296c7
Compare
Thank you @nieuwenhuisen! |
Make it possible to add extra form_row container attributes
Implement the Symfony row_attr for form_row containter attributes.
Useful if you need to add extra classes or data attributes on the container. For example:
Output:
I am targeting this branch, because it's useful from 3.x.
Changelog