joedoe
September 10, 2020, 11:12am
1
Hello,
I would like to get array of objects in this format:
“questions”: [
{ “id”: 1, “label”: “First Question” },
{ “id”: 2, “label”: “Second Question” },
{ “id”: 3, “label”: “Third Question” }
]
I use Repeater or Set format but none of these is appropriate.
Can you tell me which type of filed should I use and how to configure it?
Thank you!
I’m not aware of any core field, that has this beautiful, clean data structure. I wrote a field “simple-repeater”, that serves exactly your purpose. It wasn’t compatible with set fields (and I only tested it with text fields in the past), but I fixed it and now it should work as expected.
Field options:
name: questions
type: simple-repeater
options:
{
"field": {
"type": "set",
"label": "question",
"options": {
"fields": [
{
"type": "text",
"name": "id",
"options": {
"type": "number"
}
},
{
"type": "text",
"name": "label"
}
]
}
}
}
Custom field:
Usage:
# Simple Repeater
Custom field for [Cockpit CMS](https://github.com/agentejo/cockpit)
A simpler repeater field, than the original one. I modified the code of the original component, so credits go to @aheinze.
Copy the file `field-simple-repeater.tag` to `config/tags`
## difference to original repeater field
short answer: lesser features, cleaner output
**long answer:**
The original repeater field saved the field options in the data, too.
output of original repeater:
```json
"repeaterfield": [
This file has been truncated. show original
1 Like