-
-
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
[Form] Added additional data attributes for collections #7713
Conversation
You should also add an attribute with the prototype name. Otherwise, you have to hardcode the prototype name in the JS and it breaks when using a different value (which is needed for nested collections) |
{% if prototype is defined %} | ||
{% set attr = attr|merge({'data-prototype': form_row(prototype) }) %} | ||
{% endif %} | ||
|
||
{% if allow_delete is defined %} |
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.
it is always defined. But it may be false
you should update the rendering testsuite for these attributes, with cases testing that they are added when needed and also cases testing that they are not added when they should not. I would show you that the conditions are currently wrong and that you forgot updating the PHP templates |
Will do and resubmit. |
@leevigraham It is sufficient to push your branch again (with the |
@bschussek I think I deleted my old fork and local repo hence the new request. I'll push back up to this same PR tomorrow. |
@leevigraham ping |
@leevigraham could you finish it ? |
I'll try and work on this tonight when I get home from the office. :) On 24/04/2013, at 7:10 PM, Christophe Coevoet [email protected] wrote:
|
@stof How would you feel about adding |
@leevigraham Can you submit a PR on the docs? |
@@ -1747,7 +1751,31 @@ public function testCollectionPrototype() | |||
$this->assertMatchesXpath($html, | |||
'//div[@id="name_items"][@data-prototype] | |||
| | |||
//table[@id="name_items"][@data-prototype]' | |||
//table[@id="name_items"][@data-prototype]' | |||
); |
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 and the following tests should be split across AbstractDivLayoutTest and AbstractTableLayoutTest. We want to test that div layouts contain no tables and vice versa.
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.
The tests should also be more specific, i.e. "./table" instead of "//table".
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.
To easy. I copied the existing test but it's not hard to split. Should there be a separate test for each attribute?
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.
Not necessarily, you can test all of them in one XPath. :)
* Added additional data attributes for collections: * data-form-widget="collection" - defines that the field is a collection * data-collection-allow-delete - defines collection items can be deleted * data-collection-allow-add - defines collection items can be added * Added `prototype_name` as view variable rather than accessing prototype.vars.name * Updated .twig and php templates
@@ -1735,19 +1735,40 @@ public function testUrl() | |||
); | |||
} | |||
|
|||
public function testCollection() |
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 test doesn't really serve any purpose, since it is overridden in the subclasses anyway.
@fabpot @bschussek is there any chance to have this merged for 2.4 ? |
{% 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 comment
The reason will be displayed to describe this comment to others. Learn more.
casting a boolean to a string will display 1
or an empty string. I don't think it is the best stuff we can pass to the JS
@leevigraham have you got time to finish this one off? |
Closing in favour of a refactored and up to date w/ master: Pull Request #10071 |
I've added 4 extra data-* attributes to collections in twig and php views for easier js manipulation.
New attributes:
data-form-widget='collection'
: This is a collection and all children are form typesdata-collection-allow-add
: Allow adding of new elementsdata-collection-allow-delete
: Allow deletion of elements (new and existing)data-prototype-name
: The prototype nameThis should make javascript integration much easier.
Example js:
Replaces #5145