Iterate over a repeatable field to sum up a subfield #522
Replies: 2 comments
-
Hey @brianmurphy Maybe this example can help you on how to get all the subfields: Let me know if it doesn't 👍 Cheers |
Beta Was this translation helpful? Give feedback.
0 replies
-
Due to no activity, I will close this issue, but please feel free to re-open or create a new one if needed. Cheers. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a repeatable field for the parts needed to build my widget.
The parts repeatable has a cost subfield.
Outside of the repeatable field, I want to have a total_cost read-only field that updates when any of the cost subfields are changed.
I have viewed the javascript API FAQ but my javascript isn't strong enough to figure this out.
Here is the pseudo-code I have:
let sum = 0;
crud.field('parts').subfield('cost').onChange(function(field) {
foreach(cost as cost_subfield) {
sum += cost_subfield;
}
});
crud.field('total_cost').input.value = sum;
Now obviously that inner foreach on lines 3, 4 & 5 is wrong.
This is where I need help or a pointer to documentation on how to iterate through the subfields of a backpack repeatable field.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions