Skip to content

Commit

Permalink
Fix empty collection first item index
Browse files Browse the repository at this point in the history
  • Loading branch information
zorn-v committed Mar 14, 2024
1 parent 4127bf2 commit 248aca4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions assets/js/field-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const EaCollectionProperty = {
const nameRegexp = new RegExp(formTypeNamePlaceholder, 'g');

let newItemHtml = collection.dataset.prototype
.replace(labelRegexp, ++numItems)
.replace(labelRegexp, numItems)
.replace(nameRegexp, numItems);

collection.dataset.numItems = numItems;
collection.dataset.numItems = ++numItems;
const newItemInsertionSelector = isArrayCollection ? '.ea-form-collection-items' : '.ea-form-collection-items .accordion > .form-widget-compound [data-empty-collection]';
const collectionItemsWrapper = collection.querySelector(newItemInsertionSelector);

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/crud/form_theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
'data-entry-is-complex': form.vars.ea_vars.field and form.vars.ea_vars.field.customOptions.get('entryIsComplex') ? 'true' : 'false',
'data-allow-add': allow_add ? 'true' : 'false',
'data-allow-delete': allow_delete ? 'true' : 'false',
'data-num-items': form.children is empty ? 0 : max(form.children|keys),
'data-num-items': form.children is empty ? 0 : max(form.children|keys) + 1,
'data-form-type-name-placeholder': prototype is defined ? prototype.vars.name : '',
}) %}

Expand Down

2 comments on commit 248aca4

@YuriiZhura
Copy link

@YuriiZhura YuriiZhura commented on 248aca4 May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error after this update.
An exception has been thrown during the rendering of a template ("Unsupported operand types: string + int").
'data-num-items': form.children is empty ? 0 : max(form.children|keys) + 1,
@zorn-v can you fix this?

@zorn-v
Copy link
Contributor Author

@zorn-v zorn-v commented on 248aca4 May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in #6280

Please sign in to comment.