Related Items Validation
- gregory.murillo
- Posts: 5
- Joined: Tue Mar 14, 2017
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.
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.
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Gregory,
One thing you can do is check the amount of rows in Related Items, like this:
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;
}
Cheers
- gregory.murillo
- Posts: 5
- Joined: Tue Mar 14, 2017
Hi Nikita,
Thank you for your response. I will try it.
Kind Regards,
Thank you for your response. I will try it.
Kind Regards,
- gregory.murillo
- Posts: 5
- Joined: Tue Mar 14, 2017
Hello Nikita,Nikita Kurguzov wrote: ↑16 Mar 2018Dear 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; }
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,
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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:
But yes, as you've noticed, 1 is the default value and you need to check that the actual value is above 1.
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;
Cheers
- gregory.murillo
- Posts: 5
- Joined: Tue Mar 14, 2017
Thank you Nikita. I am using server side rendering, so it explains why it was not working.
Thanks.
Thanks.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 18 guests