Related Items Validation

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
gregory.murillo
Posts: 5
Joined: Tue Mar 14, 2017

15 Mar 2018

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.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

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;
}
Cheers

User avatar
gregory.murillo
Posts: 5
Joined: Tue Mar 14, 2017

22 Mar 2018

Hi Nikita,

Thank you for your response. I will try it.

Kind Regards,

User avatar
gregory.murillo
Posts: 5
Joined: Tue Mar 14, 2017

26 Mar 2018

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,

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Mar 2018

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.
Cheers

User avatar
gregory.murillo
Posts: 5
Joined: Tue Mar 14, 2017

28 Mar 2018

Thank you Nikita. I am using server side rendering, so it explains why it was not working.

Thanks.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests