Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added collection count when adding new rows to a collection. #528

Closed
wants to merge 1 commit into from

1 participant

@fran6co

This makes possible to use custom scripts for each row, as it allows to have unique ids for each row.

Using http://symfony.com/doc/current/reference/forms/types/collection.html#adding-and-removing-items as a reference.

@fran6co fran6co Added collection count when adding new rows to a collection. This mak…
…es possible to use custom scripts for each row, as it allows to have unique ids for each row.
3eab89b
@fran6co

I found some other way to do it

@fran6co fran6co closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 30, 2012
  1. @fran6co

    Added collection count when adding new rows to a collection. This mak…

    fran6co authored
    …es possible to use custom scripts for each row, as it allows to have unique ids for each row.
This page is out of date. Refresh to see the latest.
View
4 Resources/public/base.js
@@ -154,7 +154,9 @@ var Admin = {
var container = jQuery(this).closest('[data-prototype]');
var proto = container.attr('data-prototype');
- proto = proto.replace(/\$\$name\$\$/g, '');
+ var count = container.attr('data-count');
+ proto = proto.replace(/\$\$name\$\$/g, count);
+ container.attr('data-count',++count);
jQuery(proto).insertBefore(jQuery(this).parent());
});
View
1  Resources/views/Form/form_admin_fields.html.twig
@@ -125,6 +125,7 @@ file that was distributed with this source code.
{% if prototype is defined %}
{% set child = prototype %}
{% set attr = attr|merge({'data-prototype': block('collection_widget_row') }) %}
+ {% set attr = attr|merge({'data-count': form | length }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
Something went wrong with that request. Please try again.