-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Added additional data attributes for collections #7713
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,22 @@ | |
|
||
{% block collection_widget %} | ||
{% spaceless %} | ||
|
||
{% set attr = attr|merge({ | ||
'data-form-widget': 'collection', | ||
'data-collection-allow-add': allow_add, | ||
'data-collection-allow-delete': allow_delete, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casting a boolean to a string will display |
||
}) %} | ||
|
||
{% if prototype is defined %} | ||
{% set attr = attr|merge({'data-prototype': form_row(prototype) }) %} | ||
{% set attr = attr|merge({ | ||
'data-prototype-name': prototype_name, | ||
'data-prototype': form_row(prototype) | ||
}) %} | ||
{% endif %} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the empty lines and line breaks introduced here appear in the final HTML? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they will be removed by the |
||
{{ block('form_widget') }} | ||
|
||
{% endspaceless %} | ||
{% endblock collection_widget %} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
<?php $attr['data-form-widget'] = 'collection' ?> | ||
<?php $attr['data-collection-allow-add'] = $allow_add ?> | ||
<?php $attr['data-collection-allow-delete'] = $allow_delete ?> | ||
|
||
<?php if (isset($prototype)): ?> | ||
<?php $attr['data-prototype-name'] = $prototype_name; ?> | ||
<?php $attr['data-prototype'] = $view->escape($view['form']->row($prototype)) ?> | ||
<?php endif ?> | ||
<?php echo $view['form']->widget($form, array('attr' => $attr)) ?> | ||
<?php echo $view['form']->widget($form, array('attr' => $attr)) ?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1735,19 +1735,40 @@ public function testUrl() | |
); | ||
} | ||
|
||
public function testCollection() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't really serve any purpose, since it is overridden in the subclasses anyway. |
||
{ | ||
$form = $this->factory->createNamed('name', 'collection', array('a', 'b'), array( | ||
'type' => 'text', | ||
)); | ||
|
||
$html = $this->renderWidget($form); | ||
$this->assertWidgetMatchesXpath($html, array(), | ||
'//div[@data-form-widget="collection"]' | ||
); | ||
} | ||
|
||
public function testCollectionPrototype() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should be moved to the AbstractDivLayoutTest |
||
{ | ||
$form = $this->factory->createNamedBuilder('name', 'form', array('items' => array('one', 'two', 'three'))) | ||
->add('items', 'collection', array('allow_add' => true)) | ||
->add('items', 'collection', array( | ||
'allow_add' => true, | ||
'allow_delete' => true, | ||
'prototype_name' => '__item__' | ||
)) | ||
->getForm() | ||
->createView(); | ||
|
||
$html = $this->renderWidget($form); | ||
|
||
$this->assertMatchesXpath($html, | ||
'//div[@id="name_items"][@data-prototype] | ||
| | ||
//table[@id="name_items"][@data-prototype]' | ||
'//div | ||
[@data-form-widget="collection"] | ||
[@id="name_items"] | ||
[@data-prototype-name="__item__"] | ||
[@data-prototype] | ||
[@data-collection-allow-add="1"] | ||
[@data-collection-allow-delete="1"] | ||
' | ||
); | ||
} | ||
|
||
|
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.
Why "data-form-widget" and not "data-form-type"?
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 was thinking form-widget could eventually be applied to all form rendering. If that was the case for the date form type you would have multiple widgets. Given that any js functionality is widget specific (choice, text, single text) rather than type I thought
data-form-widget
was more specific.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.
@bschussek Are you ok with the reasoning for this change?
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.
Ping @bschussek
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.
Fine by me! :)