Skip navigation
davidcornett
Currently Being Moderated

How to efficiently check if ANY field in the form is not null

Mar 29, 2012 2:14 PM

Hi,

 

I'm guessing there's a way to programmatically check if any field has been entered when the form loads.  Some sort of loop should do the trick...

 

I've tried using the following code (from dohanlon for another purpose) which should run through all form fields, but I can't seem to plug it into an if/else statement or even check for any non-null value. 

xfa.resolveNodes("form1..#field[*]");

 

 

 

Here's conceptually how I'd like to do it:

 

if (xfa.resolveNodes("form1..#field[*\]".rawValue != null  ) {

do it

}

 

 

I'm basically trying to check if any field is not null, then I can "do something".  I know I can't use that to check .rawValue but I can't think of anything else. 

I would appreciate any help (as always). 


 
Replies
  • Currently Being Moderated
    Mar 29, 2012 4:23 PM   in reply to davidcornett

    Hi,

     

    I prefer loops, as you can build in a bit of error handling as well.

     

    See an example here: http://assure.ly/H1ksGR.

     

    Hope that helps,

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 29, 2012 4:26 PM   in reply to davidcornett

    resolveNodes method will only return a list of objects which you need to loop through.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 1:33 AM   in reply to davidcornett

    Hi David,

     

    Niall is probably right about a loop giving you more control, but you could try;

     

    if (xfa.resolveNodes('form1..#field.[ui.oneOfChild.className <> "button" and not HasValue($)]').length > 0)

    {

        // do something

    }

     

    (butttons always return seem to return a null value)

     

    Just another way to try.

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 12:03 PM   in reply to davidcornett

    Hi,

     

    Call the below method on click of a button it will check all the fields and subform fields recursively.

    Note:Make necessary changes as per comment.

     

    function nullCheckAllFields(myParentObject){

     

        var allChildElements;

        var intNumElements;

        var currentElement;

        var j;

     

        //Get all the child nodes of the parent element

        allChildElements = myParentObject.nodes;

     

        //Total number of element in the object

        intNumElements = allChildElements.length;

     

        //Loop through all the child elements

        for(j=0; j< intNumElements;j++){

            currentElement = allChildElements.item(j);

            //If the element is another subform we'll recusively call the function again

            if(allChildElements.item(j).className == "subform"){

                nullCheckAllFields(currentElement);

            }   

            //If the objects are fields or exclusive groups then we'll check them, null or not

            else if(currentElement.className == "field" || currentElement.className == "exclGroup")

            {

                if(currentElement.rawValue==null)//Exclude the fields for that you don't want to check like button etc.

                {

                    //do whatever you want to do

                   // break;//use break if want to check one at a time

                }

            }

        }   

    }//end function

     

     

    Thanks

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 10:11 AM   in reply to davidcornett

    Hi,

     

    I have specifically turned off the field highlighting, as I don't want this on. It would contradict the scripted highlighting of mandatory fields that have failed. See the script in the docReady event of the root node (form1):

     

    // Turn off the highlight colour for fields
    app.runtimeHighlight = false;
    

     

    The above script turns off the highlighting, but I find that the Document Message Bar (purple banner) tends to show/not show depending on the type of PDF opened. Because I don't have a "real" submit button, the purple banner isn't visible. If you did have a Submit button the purple banner would be present, however the above script would still turn off the actual highlighting. Make sense?

     

    Because I am specifically/only applying a red border to fields that fail validation (using script), then yes the script you copied is removing the red border if the field subsequently passes validation.

     

    When I developed this example initially, you will see that in the exit event of the root node I am calling the onExit function to clear the red border if it passes validation. The intention was that this event was propagated, so that it would be called when the user exits every field. However propagation is not supported in Acrobat/Reader version 8.1.

     

    Parallels Desktop.png

     

    Hope that helps,

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 10:56 AM   in reply to davidcornett

    Hi David,

     

    I am fairly sure I havent. For example, if you drg on a Submit by Email button, I am sure the Document Message Bar will be visible.

     

    Give it a try,

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 11:10 AM   in reply to davidcornett

    Hi,

     

    The behaviour is more determined by Acrobat/Reader than LC Designer. The Document Message Bar changes depending on what is happening in the PDF. For example if the JavaScript trust is triggered, then the Document Message Bar is yellow.

     

    See a discussion here: http://forums.adobe.com/message/3796028#3796028.

     

    I would get too worries about it. My general preference is to have the Document Message Bar hidden. But in the example form I don't think I have scripted for this, other than turning off the highlighting.

     

    Niall 

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points