Repeater area load input

Load JSON data into a ChronoForms 6 repeater area for editing.

Overview

The issue occurs when saved JSON data from a repeater area is not automatically populated back into the form inputs during an edit operation.
Decode the JSON in the 'found event' of 'read_data' to create an array, then use that array as the data provider for the repeater area and its individual fields.

Answered
ChronoForms v6
pe peppelaria 18 Apr, 2018
Hi Max. I'm using chronoforms 6 and i'm facing a problem with repeater area.
I Just created a repeater area with inputs and I already managed to set it up and save te values in json format.
What is the best way to load json and populate the repeater inputs from read_data in order to edit saved data?
pe peppelaria 19 Apr, 2018
Hi Max; I just figured it out how to get my form working.

Chronoforms 6 is really fantastic.
Gr GreyHead 19 Apr, 2018
Hi peppelaria,

Well done - please can you post the solution you found as that will help other users (including me).

Bob
pe peppelaria 20 Apr, 2018
Answer
Hi Bob. below the solution.

In the “found event” of “read_data” put a php to decode json saved before looping repeater area input.
The json format looks like: “[{"installment":"1000"},{"installment":"200"},{"installment":"300"}]
Below is the php code use to decode and loop:
$installments_array = array();

$jsondec = json_decode($this->get("read_data7.Product.installments"), true);

$i = 0;
foreach ($jsondec as $json) {
$a = $json['installment'];
$installments_array["installments[".$i."][installment]"] = $a;
$i++;
}

$this->data("installments_array", $installments_array, true);
once the array is filled, put “{data:installments_array}” in the data provider of repeater area and “{var:area_repeater_name.row}” in the data provider of the text field and that’s it.
The repeater will instantiate as many text field as the array elements number filed up with respective values
This topic is locked and no more replies can be posted.