Page 1 of 1
Related Items Validation
Posted: 15 Mar 2018
by gregory.murillo
Hello,
I have the following situation: There is a master forms which has a related items. I am looking for a way to validate if it has lines. if yes form can be submitted. If not, a popup will be displayed to the user.
Does related item componet has a property that I can check for?
Thanks a lot.
Re: Related Items Validation
Posted: 16 Mar 2018
by Nikita Kurguzov
Dear Gregory,
One thing you can do is check the amount of rows in Related Items, like this:
Code: Select all
fd.onsubmit(function(){
if(fd.relatedItems(0).data('ctx').ListData.Row.length == 0){
alert("Add items, please!");
return false;
}
return true;
}
Re: Related Items Validation
Posted: 22 Mar 2018
by gregory.murillo
Hi Nikita,
Thank you for your response. I will try it.
Kind Regards,
Re: Related Items Validation
Posted: 26 Mar 2018
by gregory.murillo
Nikita Kurguzov wrote: ↑16 Mar 2018
Dear Gregory,
One thing you can do is check the amount of rows in Related Items, like this:
Code: Select all
fd.onsubmit(function(){
if(fd.relatedItems(0).data('ctx').ListData.Row.length == 0){
alert("Add items, please!");
return false;
}
return true;
}
Hello Nikita,
This call fd.relatedItems(0).data('ctx').ListData.Row.length always returns null. In fact ListData property is always null, so function crashes with an error.
Instead, I found that fd.relatedItems(0).data('ctx').clvp.tab.rows.length always has a value. If length has a value of 1, it means there are no rows other than header. If length has a value greater than 1, it means rows have been added to the RelatedItems.
Can you confirm if that is correct? I am bit confused, since I don't know if it has do to with the current SPFormDesigner version we have. I am calling it from Edit Form and not from NewForm, if that makes sense.
Regards,
Re: Related Items Validation
Posted: 27 Mar 2018
by Nikita Kurguzov
Dear Gregory,
That depends on the configuration of Related Items. The code I've given should work with both Quick Edit and Regular mode of Related Items, as long as you use Client side rendering. If you are using Server side rendering, it will not work.
Your code should work for Server side rendered Related Items control:
Code: Select all
fd.relatedItems(0).data('ctx').clvp.tab.rows.length;
But yes, as you've noticed, 1 is the default value and you need to check that the actual value is above 1.
Re: Related Items Validation
Posted: 28 Mar 2018
by gregory.murillo
Thank you Nikita. I am using server side rendering, so it explains why it was not working.
Thanks.