Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Validate field if it's null and visible

Avatar

Level 7

I have a table that is sometimes hidden. I want to validate the cells  in the table, but only if the table is visible. I found this script on the Forum, but am having trouble making it work. The error message appears when the table is hidden.

 

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);

}

Thanks,

MDawn

1 Accepted Solution

Avatar

Correct answer by
Level 7

Thanks. I’ll give that a try.

Margaret Dawn

View solution in original post

10 Replies

Avatar

Level 10

You are missing rawValue for the TextField.

Do you have form1 in your Heirarchy (OR) the root subform is partiv?

if(partiv.nonflow.busjus.presence == "visible" && partiv.nonflow.busjus.TextField13.rawValue == null)

{

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

}

else {

     myScriptObject.LockAllFields(form1);

}

Thanks

Srini

Avatar

Level 7

Sorry I wasn’t clear enough. I had updated the script to fit my form and had added the rawValue. The script works to check for null and gives the error message, but does this even if the table row is hidden. I want it to only display the error message if the row is visible.

Thanks,

Margaret Dawn

Avatar

Level 10

Try this..

if(partiv.nonflow.busjus.presence == "visible")

{

     if(partiv.nonflow.busjus.TextField13.rawValue == null || partiv.nonflow.busjus.TextField13.rawValue == "")

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

     else

          myScriptObject.LockAllFields(form1);

}

Thanks

Srini

Avatar

Level 7

The error message still appears when the field is hidden. Nothing is listed when I check Ctrl+J.

Thanks,

Margaret Dawn

Avatar

Level 10

Can you share your form..

Steps to share a document..

1. Go to URL http://Acrobat.com
2. Create an account if you don't have one.
3. Then login to the website.
4. In top left corner you will see a button called Upload.
5. Click on browse and select the file you want to upload.
6. After Uploading, mouse over on the uploaded file. Click the down arrow button and choose Share document.
7. Then you will be prompted a popup window at the lower left corner. Choose "Publish it" option.
8. In the next pop up window choose "Copy Link" option.
9. You can paste the link in the forum thread.

Thanks

Srini

Avatar

Level 7

I've shared the form I'm working on.

https://acrobat.com/#d=SVmH2o-aCAIxnHTAiZpXHw

Great instructions, by the way!

Thanks,

MDawn

Avatar

Level 10

In the form that you shared,

     1) You are setting the presence property for the Table to be Hidden.

          So your code should check for the Table's presence value and not the TextField4's presence property.

      

          Change your code to make it work in the sample you shared.

                  if(Table2.presence == "visible")

Thanks

Srini

Avatar

Correct answer by
Level 7

Thanks. I’ll give that a try.

Margaret Dawn

Avatar

Level 7

I took the working script from the experiment form I had created. I put the script in an actual form where I have 3 hidden subforms that may be displayed depending on the selection in 2 ddls. Now the script that was working is not, at all. Note, I have used 3 invisible buttons with the scripts on the click event of each one. Any help would be appreciated. I'm having trouble uploading the form, so here's a sample of one of the scripts:

if(voidTrx.presence == "visible")
{
  else if(voidTrx.table2.Table2.Row1.TextField4.rawValue == null || voidTrx.table2.Table2.Row1.TextField4.rawValue == "")
      app.alert('Please the transaction number.');  

else (voidTrx.table2.Table2.Row1.TextField5.rawValue == null || voidTrx.table2.Table2.Row1.TextField5.rawValue == "")
      app.alert('Please enter the register number.');
     
else (voidTrx.table2.Table2.Row1.TextField6.rawValue == null || voidTrx.table2.Table2.Row1.TextField6.rawValue == "")
      app.alert('Please enter the till number.');
     
else (voidTrx.table2.Table2.Row1.DropDownList2.rawValue == null || voidTrx.table2.Table2.Row1.DropDownList2.rawValue == "")
      app.alert('Please select the type of tender.'); 

else
     Button5.execEvent("click");

There are 4 fields in the table row that I need to check for.

Thanks,

MDawn
}

Avatar

Level 10

Try the below modified code..

strText4 = voidTrx.table2.Table2.Row1.TextField4.rawValue;
strText5 = voidTrx.table2.Table2.Row1.TextField5.rawValue;
strText6 = voidTrx.table2.Table2.Row1.TextField6.rawValue;
strDDList = voidTrx.table2.Table2.Row1.DropDownList2.rawValue;


if(voidTrx.presence == "visible")
{
  if(strText4 == null || strText4 == "")
      xfa.host.messageBox("Please the transaction number.");
else if(strText5 == null || strText5 == "")
      xfa.host.messageBox("Please enter the register number.");
else if(strText6 == null || strText6 == "")
      xfa.host.messageBox("Please enter the till number.");
else if(strDDList == null || strDDList == "")
      xfa.host.messageBox("Please select the type of tender.");
else
     Button5.execEvent("click");
}

Thanks

Srini