Javascript Library read subfield repeatable field #897
-
I have a repeatable field with a subfield called 'subtotal' i want to read each subfield subtotal present in each row of the repeatable. How can i achieve this? |
Beta Was this translation helpful? Give feedback.
Answered by
karandatwani92
Mar 28, 2024
Replies: 1 comment 1 reply
-
Hey @aberaldo The Try: crud.field('features').onChange(function(field) {
var i = 1;
var total = 0;
while ((crud.field('features').subfield(`subtotal`,i).value != undefined)) {
var subtotal = crud.field('features').subfield(`subtotal`,i).value; //subfield() supports row number argument.
console.log("subtotal",subtotal);
total+=Number(subtotal);
i++;
}
console.log("total",total);
}).change(); @pxpm can you suggest a better way to loop ? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pxpm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @aberaldo
The
subfield()
supports the row number argument.Try:
@pxpm can you suggest a better way to loop ?