Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Dynamic subform validation

Avatar

Level 4
Hi there



I have a form that when you click a button it repeats an instance of a subform.



I have also added an additional 'validation' button so that it checks that some of the fields in the subform are filled in. I have used some JavaScript for this. The validation works fine on the first instance. However, it does not work on the second instance on the subform. I know that somehow I must get the script to check for extra instances but I cannot work it out.



Any help would be greatly appreciated.



Thanks
4 Replies

Avatar

Former Community Member
You will have to put your code in a for loop where you can get the count of subforms to test. Now that you know the number of times to loop through the for loop, you can access each individual item of the subform using this notation:



form1.Page1.subform1.repeatingsubform[x].fieldname.property/method



To be able to derive the Som Expression and use the counter in the for loop you can use this notatoin:



xfa.resolveNode("form1.Page1.subform1.repeatingsubform[" + counter + "]").fieldname.....



This allows your expression to increment as the counter increments and will update each row as required. Note that the instance numbers are 0 based.

Avatar

Level 4
Hi Paul



Many thanks for your reply. I am new to LiveCycle and picking up things and learning as I go along so I didnt fully grasp where to input the code or if it needs to go into a different event. Would you be able to put your example into context with the validation script I have runnning on the click event of a button in my form.



if ((HigherEducationPage.QualificationSubform.course.rawValue == null) || (HigherEducationPage.QualificationSubform.course.rawValue == "")) {

app.alert("Please enter your course in Section 1 of this form.");



Many thanks



Darren

Avatar

Level 4
Also can you explain how the for loop works as well and where I would need to add it in.



Thanks again



Darren

Avatar

Former Community Member
It woudl be easier to add the code and show you that way. If you send the file to livecycle8@gmail.com I will add the code when I get a chance.