I need to set the value of a data field depending on which instance of a component was clicked inside a repeat.
Each instance of the component inside the repeat has a fieldref pointing to the data field and i can easily read the value of the data field by using
path = Form.getItemProperty("data.product","dataFieldReference");console.log(Form.getPathData(path, Form.data)); // prints the value of the datafield
But when i try to set it's data
path = Form.getItemProperty("data.product","dataFieldReference");Form.setPathData(path, 'new value');
It throws a TypeError: Cannot set property '<<value of path>>' of undefined. My best guess it is due to the context of the data (because it's inside the repeat), but I can't find any way to specify the context. I've already tried with Form.setPathData(path, 'new value', Form.data) but it throws the same error.
The code is running inside the repeat and is trying to modify a data field out of the repeat.
I think i have found the issue: I double clicked the field that i wanted to modify, so it got a value like data.$p.dataField, however however getPathData and setPathData were not able to find the reference because (i think) '$p' is not a valid path expresion so i changed my fieldRef value to Form.data.dataField and it worked. Can you confirm this? And if thats the case, just out of curiosity, how should we use fieldRefs when working with nested repeats?
It's important to know where the code is running. Is the code running inside the context of the repeat (in other words, is it attached to one of the components inside the repeat)?
Or is it running outside the repeat?
This video may be helpful: https://support.avoka.com/kb/display/TKB/All+about+repeating+data