getgrav / getgrav/grav-plugin-admin

Reindexation when an array field is placed in a list field

Open
#1,504 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
PHP
Stars
377
Forks
225
Avg merge
11h 51m
Merged PRs (30d)
4

Description

Hello,

Reindexation of array fields seems not to be done when reordering or adding entries in lists.

Multiple effects :
* Last submitted list entry to split.

* Link array field value to another list entry when modifying values after reordering list entries

**How to reproduce :**

Create a new template with a blueprint containing a list with an array and another field :
```yaml
title: 'Check'
'@extends': default

form:
fields:
tabs:
fields:
test:
type: tab
title: Test
fields:
header.testList:
name: testList
type: list
label: Test List
fields:
.text:
type: text
name: testText
label: Test Text
.testArray:
type: array
label: TestArray
```

Create a page with using this template, then in the form add an item to the test list using the add button of the list field.
Fill the test Text and first fields from the testArray.
Then save the page. The text and the array values should be splitted in two entries.

I noticed that `data-grav-array-name` attribute on the root div of the array field got value `"data[header][testList][*][testArray]"` and first line value input got `data[header][testList][0][testArray]`. As soon as you modify the value or key it turns into `data[header][testList][*][testArray][key]`. If you modify all '*' in attributes values into '0' before saving, it works as expected.

**Possible fix :**
It seems like the problem is coming from the reindex method in collections.js that does not reindex attributes `data-grav-array-name`. Adding it in array on line 176 might solve the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.