Expand my Community achievements bar.

SOLVED

Using javascript code to validate contents in text field only if the text field is visible . . .

Avatar

Level 2

I have a "Lock All Fields" button set up and it's set to run only if certain fields are completed. The code works fine... except TextField13 does not validate properly. TextField13 is wrapped within a subform entitled busjus. The busjus subform is hidden from the form layout by default (it only becomes visible if a user selects certain text from a dropdown list). I want the code to check if TextField13 is null only if the busjus subform is visible.

The problematic part of the code that is not working as intended is listed below:

partiv.nonflow.busjus.presence == visible) && partiv.nonflow.busjus.TextField13 == null ||  

Full code is listed below:

if(partiandii.parti.TextField2.rawValue == null ||

partiandii.parti.TextField1.rawValue == null ||

partiandii.parti.DropDownList5.rawValue == null ||

//Part II: Current Job Details

partiv.nonflow.busjus.presence == visible) && partiv.nonflow.busjus.TextField13 == null || 

partiandii.partii.NumericField2.rawValue == null ||)

{

    app.alert('Please complete all fields marked with a red asterisk and try clicking the button again.');  

}

else {

    myScriptObject.LockAllFields(form1);

}

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi,

At a quick look I think this piece needs to include the rawValue call

partiv.nonflow.busjus.TextField13

this should be

partiv.nonflow.busjus.TextField13.rawValue

so that you are comparing the text in the field rather than the actual field object.

Hope this helps

Malcolm

View solution in original post

4 Replies

Avatar

Level 10

Hi,

Unless you have defined a variable called visible with a value of "visible" I think you will need to put visible in quotes.  There also seems to be a problem with an extra bracket after visible and an extra "II" or operator at the end.  So in Designer try the "Check script syntax" option under the tools menu.  Also you should have the option set in Reader/Acrobat to show the console when a syntax error is displayed.

So try this;

if(partiandii.parti.TextField2.rawValue == null ||
   partiandii.parti.TextField1.rawValue == null ||
   partiandii.parti.DropDownList5.rawValue == null ||

//Part II: Current Job Details

   partiv.nonflow.busjus.presence == "visible" && partiv.nonflow.busjus.TextField13 == null || 
   partiandii.partii.NumericField2.rawValue == null)
   {
    app.alert('Please complete all fields marked with a red asterisk and try clicking the button again.');  
   }
else
   {
    myScriptObject.LockAllFields(form1);
   }

Good luck

Bruce

Avatar

Level 2

Still not working..

I've got rid of all the other variables to narrow down this piece of code:

if(partiv.nonflow.busjus.presence == "visible" && partiv.nonflow.busjus.TextField13 == null)
{
     app.alert('Please complete all fields marked with a red asterisk and try clicking the button again.');  
}
else {
     myScriptObject.LockAllFields(form1);
}

The above code (attached to a button's click event) locks all the input fields as it should, however if the TextField13 box is visible and empty, it still doesn't check to see if there is text in the field and all the fields on the form lock anyway...

There are no errors in my code when I click "check syntax."

Avatar

Correct answer by
Level 5

Hi,

At a quick look I think this piece needs to include the rawValue call

partiv.nonflow.busjus.TextField13

this should be

partiv.nonflow.busjus.TextField13.rawValue

so that you are comparing the text in the field rather than the actual field object.

Hope this helps

Malcolm

Avatar

Level 2

Thanks so much Barlae! I can't believe I didn't notice I was missing the rawValue... I've been working on this form way too much in the past couple of days!