why ajax calculation is not working when you sum a repeteable group datas?

javier94

Member
I have 3 columns in a repeteable group..

column 1 = are months numbers
column 2 = a dropdown with 3 items...

0 ---> " ---" --> value --> "0"
1 --> " no related" --> value "0"
2--> " related" --> value " number appears in column 1"

column 3 = value of column 1.. if you change the dropdown...

i show you the image..

repeteable-sum-1.png

if i save the form.. when i enter again.. the value is ok.. but the point is..

I need to see the value.. when i change the dropdown.. ( column 2) because there are some elements that
should make a calculation after the sum of repeteable..

the code use for calculation in column 3 is...

$var = '{merits_candidats_815_repeat___relacionada_public_1_raw}';
if ($var == "2"){
$res = '{merits_candidats_815_repeat___mesos_public_1}';
} else {
$res = "0";
}
return $res;

Ajax observe fields
'{merits_candidats_815_repeat___relacionada_public_1_0}'

---------
And the code to obtain sum value from repeteable ( i saw in other post)

$amounts = (array) $data['merits_candidats_815_repeat___value_public_1_raw'];
return '?' . array_sum($amounts);

ajax observe fields

{merits_candidats_815_repeat___value_public_1_0},
{merits_candidats_815_repeat___relacionada_public_1}


any suggestion... ??

Thanks
 
The calc element was never really designed to work with repeat groups. Over the years I've kind of hacked it to kinda work, so if your calc is only referencing other elements within the same repeat instance, or elements on the main (non repeat) group(s), it'll work. But when you start trying to do things like sum all the elements in a repeat, it's going to be problematic.

It's also really hard to diagnose this kind of thing just reading a post.

I think the only way forward would be for you to talk to @mediaateam, and purchase a few hours of on site support, so I can get my hands on it.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top