Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Show/Hide Fields Based on Dropdown

Avatar

Level 3

Hi,

I am attempting to show/hide subforms with a dropdown selection. I've found a lot of information on the subject, and have ended up with this as my script:

form1.Page1.Division::exit - (JavaScript, client)

switch (Page1.Division.rawValue)
{
   case "1":
   SubformZZI.presence = "visible";
   SubformZZR.presence = "hidden";  
      break;

   case "2":
   SubformZZI.presence = "hidden";
   SubformZZR.presence = "visible";      
      break;
}

However, it is not doing anything when a selection is made in the dropdown box. I have the "SubformZZI" initially set as "Visible" and the "SubformZZR" initially set as "Hidden".

Any suggestions?

Regards,

ZeroZone

1 Accepted Solution

Avatar

Correct answer by
Level 10

Check if the form is saved as Dynamic form. File -> Save As and choose dynamic for the form type..

Other than that, you need to check whether you have given the values for the Dropdown selection as "1" and "2" in the binding tab of the control.

Thanks

Srini

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

Check if the form is saved as Dynamic form. File -> Save As and choose dynamic for the form type..

Other than that, you need to check whether you have given the values for the Dropdown selection as "1" and "2" in the binding tab of the control.

Thanks

Srini

Avatar

Level 3

Thanks Srini,

It appears that part of it is working fine now.

However, I can't get my Submit button to work now. This is the code on my Submit button. Anyone see anything incorrect?

form1.Page1.Submit::click - (JavaScript, client)

// First check if there are null values, then construct email using script
var vEmail = "";
var vSubject = "";
var vBody = "Attached to this email is a Field Service Issue - Parts Order Form for Job #" + Page1.JobNumber.rawValue + ".";
var vName = "";
var vCC =  "name@zero-zone.com" + "," + Page1.RSM.rawValue + "," + Page1.IssueLeaderEmail.rawValue; 
var vFormat = "PDF";
var errorMessage = "At least one required field was empty. Please fill in the required fields (highlighted) before continuing."; 

// Check required fields and build error message
if (Page1.IssueLeaderEmail.rawValue == null)
{
     errorMessage = errorMessage;
}
else
{
     vSubject = "Field Service Issue - Parts Order Form for Job #" + Page1.JobNumber.rawValue;
}

// Check Division field
if (Page1.Division.rawValue == "Case Division")
{
     vEmail = Page1.SendFormToZZI.rawValue;
     vCC = Page1.SendCopyToZZI.rawValue + "," + Page1.CSTZZI.rawValue;
}
else
{
     vEmail = Page1.SendFormToZZR.rawValue;
     vCC = Page1.SendCopyToZZR.rawValue + "," + Page1.CSTZZR.rawValue;
}

// If fields required for script are null, warn user and do not initiate email
if (Page1.IssueLeaderEmail.rawValue == null || Page1.Division.rawValue == "null")
{
     xfa.host.messageBox(errorMessage, "Sending an email", 0, 0); // Send out a custom error message if any of these fields are null
}
else
{
     // Everything is OK, send email
     event.target.submitForm({cURL:"mailto: "+ vEmail +"?subject=" + vSubject +"&body=" + vBody + "&cc=" + vCC,cSubmitAs:vFormat,cCharset:"utf-8"});
}

Regards,

ZeroZone

Avatar

Level 10

Put some debug message statements to see if all the IF conditions are met.

The only change I made to your code is highlighted below..

event.target.submitForm({cURL:"mailto: "+ vEmail +"?cc=" + vCC + "&subject=" + vSubject +"&body=" + vBody ,cSubmitAs:"PDF",cCharset:"utf-8"});

See if this helps..

Thanks

Srini

Avatar

Level 3

Thank you, but unfortunately, that doesn't seem to be working.

Regards,

ZeroZone

Avatar

Level 10

You have wrongly referenced the fields in your code.

Copy and paste the below code in the click event of the Submit button. It should work as expected.

The code thathas error is commented..

// First check if there are null values, then construct email using script
var vEmail = "";
var vSubject = "";
var vBody = "Attached to this email is a Field Service Issue - Parts Order Form for Job #" + Page1.JobNumber.rawValue + ".";
var vName = "";
var vCC =  "greg.gustafson@zero-zone.com" + "," + Page1.RSM.rawValue + "," + Page1.IssueLeaderEmail.rawValue; 
var vFormat = "PDF";
var errorMessage = "At least one required field was empty. Please fill in the required fields (highlighted) before continuing.";

// Check required fields and build error message
if (Page1.IssueLeaderEmail.rawValue == null)
{
errorMessage = errorMessage;
}
else
{
vSubject = "Field Service Issue - Parts Order Form for Job #" + Page1.JobNumber.rawValue;
}

// Check Division field
if (Page1.Division.rawValue == "Case Division")
{
     //vEmail = Page1.SendFormToZZI.rawValue;
     vEmail = Page1.SubformZZI.SendFormToZZI.rawValue;
     //vCC = Page1.SendCopyToZZI.rawValue + "," + Page1.CSTZZI.rawValue;
     vCC = Page1.SubformZZI.SendCopyToZZI.rawValue + "," + Page1.SubformZZI.CSTZZI.rawValue;
}
else
{
     //vEmail = Page1.SendFormToZZR.rawValue;
     vEmail = Page1.SubformZZR.SendFormToZZR.rawValue;
     //vCC = Page1.SendCopyToZZR.rawValue + "," + Page1.CSTZZR.rawValue;
     vCC = Page1.SubformZZR.SendCopyToZZR.rawValue + "," + Page1.SubformZZR.CSTZZR.rawValue;
}

// If fields required for script are null, warn user and do not initiate email
if (Page1.IssueLeaderEmail.rawValue == null)
{
xfa.host.messageBox(errorMessage, "Sending an email", 0, 0); // Send out a custom error message if any of these fields are null
}
else
{
// Everything is OK, send email
event.target.submitForm({cURL:"mailto: "+ vEmail +"?subject=" + vSubject +"&body=" + vBody + "&cc=" + vCC,cSubmitAs:"PDF",cCharset:"utf-8"});
}

Thanks

Srini