Skip to content

Commit ff72820

Browse files
committed
Merge pull request #952 from molchanoviv/master
Fix for incorrect replace of prototype placeholders in nested collections
2 parents 7453e43 + 89344f9 commit ff72820

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

Resources/doc/3.1-form-collections.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,43 @@ Some things are currently missing :
6262
* examples on howto extend the functionality with check functions for adding and removing
6363
* in depth example on howto use Custom FormTypes easily
6464
65+
Nested collections
66+
----------------------
67+
68+
MopaBootstrapBundle supports nested collections. You can use them as shown below.
69+
70+
At first you need to create a child Form Type with some collection
71+
```php
72+
class MyChildType extends AbstractType
73+
{
74+
public function buildForm(FormBuilderInterface $builder, array $options)
75+
{
76+
$builder
77+
->add('mySubCollection', 'collection', [
78+
'type' => 'text',
79+
])
80+
;
81+
}
82+
}
83+
```
84+
85+
After it you need to create a parent Form Type which will use your child form type as a type of collection items.
86+
87+
```php
88+
class MyParentType extends AbstractType
89+
{
90+
public function buildForm(FormBuilderInterface $builder, array $options)
91+
{
92+
$builder
93+
->add('myCollection', 'collection', [
94+
'type' => new MyChildType(),
95+
])
96+
;
97+
}
98+
}
99+
```
100+
That's it.
101+
65102
---
66103

67104
<< [Form Extensions](https://github.com/phiamo/MopaBootstrapBundle/blob/master/Resources/doc/3-form-extension-templates.md) | [Form Tabs](https://github.com/phiamo/MopaBootstrapBundle/blob/master/Resources/doc/3.2-form-tabs.md) >>

Resources/public/js/mopabootstrap-collection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
prototype_label = '__name__label__';
7070
}
7171

72-
var name_replace_pattern = new RegExp(prototype_name, 'g');
73-
var label_replace_pattern = new RegExp(prototype_label, 'g');
72+
var name_replace_pattern = new RegExp("((\"|&quot;|'|&#039;)((?!(\"|&quot;|'|&#039;|__name__)).)+?)(" + prototype_name + ")", 'ig');
73+
var label_replace_pattern = new RegExp("((\"|&quot;|'|&#039;)((?!(\"|&quot;|'|&#039;|__name__)).)+?)(" + prototype_label + ")", 'ig');
7474
var rowContent = $collection.attr('data-prototype')
75-
.replace(label_replace_pattern, index)
76-
.replace(name_replace_pattern, index);
75+
.replace(label_replace_pattern, "$1" + index)
76+
.replace(name_replace_pattern, "$1" + index);
7777
var row = $(rowContent);
7878
if (false !== $(window).triggerHandler('before-add.mopa-collection-item', [$collection, row, index])) {
7979
$collection.append(row);

0 commit comments

Comments
 (0)