Skip to content

Commit da3a235

Browse files
AstaldosPetr Kachanovsky
andauthored
docs: add isArray description (#78)
Co-authored-by: Petr Kachanovsky <[email protected]>
1 parent 45d6b9b commit da3a235

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

adminforth/documentation/docs/tutorial/03-Customization/13-standardPagesTuning.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,65 @@ export default {
389389
],
390390
```
391391

392+
### Filling an array of values
393+
394+
Whenever you want to have a column to store not a single value but an array of values you have to set column as `AdminForthDataTypes.JSON`. This way when you are creating or editing a record you can type in a JSON array into a textfield. To simplify this process and allow you to create and edit separate items you can add `isArray` to a column.
395+
396+
```typescript title="./resources/users.ts"
397+
export default {
398+
name: 'users',
399+
columns: [
400+
...
401+
{
402+
name: "room_sizes",
403+
type: AdminForthDataTypes.JSON,
404+
//diff-add
405+
isArray: {
406+
//diff-add
407+
enabled: true,
408+
//diff-add
409+
itemType: AdminForthDataTypes.FLOAT,
410+
//diff-add
411+
},
412+
},
413+
],
414+
},
415+
...
416+
],
417+
```
418+
419+
Doing so, will result in UI displaying each item of the array as a separate input corresponding to `isArray.itemType` on create and edit pages.
420+
421+
`itemType` value can be any of `AdminForthDataTypes` except `JSON` and `RICHTEXT`.
422+
423+
By default it is forbidden to store duplicate values in an array column. To change that you can add `allowDuplicateItems: true` to `isArray`, like so:
424+
425+
```typescript title="./resources/users.ts"
426+
export default {
427+
name: 'users',
428+
columns: [
429+
...
430+
{
431+
name: "room_sizes",
432+
type: AdminForthDataTypes.JSON,
433+
isArray: {
434+
enabled: true,
435+
itemType: AdminForthDataTypes.FLOAT,
436+
//diff-add
437+
allowDuplicateItems: true,
438+
},
439+
},
440+
],
441+
},
442+
...
443+
],
444+
```
445+
446+
All validation rules, such as `minValue`, `maxValue`, `minLength`, `maxLength` and `validation` will be applied not to array itself but instead to each item.
447+
448+
Note: array columns can not be marked as `masked`, be a `primaryKey` and at the time can not be linked to a foreign resource.
449+
450+
392451
### Foreign resources
393452

394453
[Documentation in progress]

0 commit comments

Comments
 (0)