Ben
March 2, 2022, 10:32pm
1
I would like to save form input to an array in the model. I have looked on the forum and in the docs but I can’t find the syntax to define an array. I guess this should be possible?
here is what I have now, how can I make the value of “textResponse” an array?
{
"inputType": "text",
"label": "Q1",
"model": "form.textResponse1",
"type": "input"
}, {
"inputType": "text",
"label": "Q2",
"model": "form.textResponse2",
"type": "input"
},
Andrew
March 2, 2022, 11:02pm
2
You can define an array in your Data Model tab.
In the default data, you can define your array with something like
"textResponses": [{
"textResponse1": "",
"textResponse2": ""
}]
For your input fields, you can now target the textReponses array and have something like
"model": "textResponses[0].textResponse1"
If you wanted each response to be its own object in the array, you can do something like
"textResponses": [{
"textResponse1": ""
},{
"textResponse2": ""
}]
and then target the second one with
"model": "textResponses[1].textResponse2"
*Edited with right syntax
Ben
March 3, 2022, 1:45am
3
Thanks, but I’m not seeing how to just get an Array of values, not an array of objects, Maybe it can’t be done?
I would like to get is simple array of values, from my input fields, something like this:
{"form":{"textResponse":["value1","value2",..."valueN"]}}
(edited!)
is there a way to do that?
I feel like my page should look something like this, but this does not work:
{
"inputType": "text",
"label": "Q1",
"model": "form.textResponse[0]",
"type": "input"
}, {
"inputType": "text",
"label": "Q2",
"model": "form.textResponse[1]",
"type": "input"
}
Andrew
March 3, 2022, 2:09am
4
I just tried your solution and it worked for me.
Default Data Model:
"form": {
"textResponse": []
},
Page Builder:
{
"inputType": "text",
"label": "Input 1",
"model": "form.textResponse[0]",
"styleClasses": "col-md-3",
"type": "input"
}, {
"inputType": "text",
"label": "Input 2",
"model": "form.textResponse[1]",
"styleClasses": "col-md-3",
"type": "input"
}
1 Like
Ben
March 3, 2022, 11:54am
5
yes - it is that easy! Thank you, all good now.
because objects don’t need to predefined in the default data model, I was unsure how to declare an array. I see now that arrays do need to be predefined in the default data model.
(edited typos)