Expand my Community achievements bar.

How can I quickly determine whether or not a subform has data entered to it?

Avatar

Former Community Member

Hi there,

I would like to write a function that is passed a subform and returns true if no data has been entered to it, i.e. all the fields are null.  Can somebody please point me to a snippet of code that will get me started as I'm at a loss as to how to implement this?

Many thanks,

Kieran Kelly

2 Replies

Avatar

Level 10

Below is a sample code which I used to set the access of the fields inside the given subform.. You can change the access property to rawValue and reuse it..

var objSubform = xfa.resolveNode(strSubformName);
for(i=0;i<objSubform.nodes.length;i++){
  if(objSubform.nodes.item(i).className == "field"){
   objSubform.nodes.item(i).access = "protected";
  }
}

Thanks

Srini

Avatar

Former Community Member

Thanks Srini, that was very useful.

I would like to make my function recursive for when there are nested subforms.  Can you tell me how I can get the full path of a subform for feeding back into the function?

Here is the function:

function doesSubformHaveData( strSubformPath )

{

     var objSubform = xfa.resolveNode( strSubformPath ); 

     //Loop through the node of this subform and check is 'field' nodes have data.

     //Where the node is a subform put it through the same function.

     for ( i = 0; i < objSubform.nodes.length; i++ )

     {

       if ( objSubform.nodes.item(i).className == "field" )

         {

            //If the node is a field check if it has data

             if ( objSubform.nodes.item(i).rawValue != null )

                  return true; //Some data has been found so return true

          }

       else if (objSubform.nodes.item(i).className == "subform" )

       {

            //If the node is a subform put it through the same function

              if ( doesSubformHaveData( strSubformPath + "." + objSubform.nodes.item(i).name ) ) //PROBLEM LINE

                 return true; //Some data has been found so return true

        }

}

return false; //No data has been found so return true

}

The line above that I have commented with 'PROBLEM LINE' does not work if the nested subform does not have a title.  Is there a way of getting the full path of the subform without having to append the name in this way.

Thanks again,

Kieran