Skip to content

Commit d983ff7

Browse files
committed
Fixed form collection data prototype
1 parent 5022ba6 commit d983ff7

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/LIN3S/AdminBundle/Resources/private/js/components/FormCollection.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class FormCollection {
3535
this.bindRemoveListeners(nodeAddedEvent.nodes)
3636
);
3737
NodeAddedObserver.subscribe('js-form-collection-visibility-toggle', nodeAddedEvent =>
38-
this.bindVisibilityToggleListeners(nodeAddedEvent.nodes)
39-
);
38+
this.bindVisibilityToggleListeners(nodeAddedEvent.nodes)
39+
);
4040
}
4141

4242
bindAddListeners(addButtons) {
@@ -73,8 +73,8 @@ class FormCollection {
7373
event.preventDefault();
7474

7575
const collectionHolder = event.currentTarget
76-
.closest('.form-collection')
77-
.querySelectorAll('.form-collection__items')[0];
76+
.closest('.form-collection')
77+
.querySelector('.form-collection__items');
7878

7979
this.addFormType(collectionHolder);
8080
}
@@ -83,12 +83,12 @@ class FormCollection {
8383
const
8484
prototype = collectionHolder.getAttribute('data-prototype'),
8585
prototypeName = collectionHolder.getAttribute('data-prototype-name'),
86-
regExp = new RegExp(prototypeName === undefined ? '__name__' : prototypeName, 'g'),
87-
index = collectionHolder.querySelectorAll('input, textarea, select, button') !== null,
88-
newForm = prototype.replace(regExp, index);
86+
regExp = new RegExp(!prototypeName ? '__name__' : prototypeName.replace(/[\'\"]/g, () => ''), 'g'),
87+
index = collectionHolder.querySelectorAll('.form-collection__item').length,
88+
newForm = prototype.replace(regExp, index.toString());
8989

9090
collectionHolder.insertAdjacentHTML('beforeend', newForm);
91-
collectionHolder.setAttribute('data-index', index + 1);
91+
collectionHolder.setAttribute('data-index', (index + 1).toString());
9292
}
9393

9494
onClickRemoved(event) {

0 commit comments

Comments
 (0)