Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

FormCalc not working ... Hiding text field based on drop-down selection

Avatar

Level 1

I thought I was on the right path. I have a drop-down with seven options. Here is what I need: If they select RFA (value 4) then "textfield14" becomes visible. If they select any of the other choices then "table5" becomes visible and "textfield14" goes hidden. My current formula is on the right track but if I select RFA and "textfield14" shows but then I choose another option, the "textfield14" does not hide again. Thoughts?

if (DropDownList1==4)then

TextField14.presence = "visible"

elseif (DropDownList1==1 or 2 or 3 or 5 or 6 or 7) then

Table5.presence = "visible"

else TextField14.presence = "hidden"

Table5.presence = "hidden"

endif

1 Accepted Solution

Avatar

Correct answer by
Level 4
6 Replies

Avatar

Level 4

I wrote this quickly in JavaScript. You can place this code in the exit event of your dropdown box. You need to set the text box and the table properties to hidden before you write the code. For simplicity, I only put 4 values in the drop down box. The || is the "OR" statement in JavaScript.  I tested this code and it should work for you.

If you select the first or second selection in the dropdown, the table will appear. If you select the 4th choice, the textbox will appear. If you select the third option, nothing will happen.


if (this.rawValue == "4"){

form1.Page1.TextField4.presence = "visible"
form1.Page1.Table5.presence = "hidden"
}

else if (this.rawValue == "1" || this.rawValue == "2"){

form1.Page1.TextField4.presence = "hidden"
form1.Page1.Table5.presence = "visible"
}

else {

form1.Page1.TextField4.presence = "hidden"
form1.Page1.Table5.presence = "hidden"
}

Avatar

Level 1

I put that in and it did not work. I am thinking because my form has a subform and it's messy. I did try to add in the additional layers to the presence lines but it still didn't work. Take a look at the picture and let me know what you think. Is there not FormCalc for this?

livecycle.jpg

Avatar

Level 4

I developed a test of that code and it worked per your original question.  Usually if the code is not working, it is an object reference issues, not a code issue.

Yes, you can do the same thing if you wish to use FormCalc. If you send me the form, or post the form on dropbox, I can put the code in there for you.

Avatar

Level 4

I received your form. I did a quick mock-up and included working FormCalc code in your drop box field.

As I surmised, your code actually worked, to a degree. Generally, in hide/display events, you need to include both elements in each if/then condition statement in order to ensure that if a user hits the wrong entry, then corrects, both fields are not visible..

Other items for consideration:

  1. You used tables repeatedly to display text fields. Tables are more problematic to work with; in my example, I just used text boxes, wrapped in sub-forms.
  2. Table are generally used only when: (1) you want to add specifically defined table rows (or perform some other math); or (2) when you need to invoke the instance manager and have your table expand rows. Otherwise, using fields and sub-forms is much easier.
  3. In your hierarchy, you have not named all fields. This could result in a two fields having the same name.
  4. Generally, only collect only one data element per field (e.g., I separated PM/CM from phone).
  5. You can uses flowed and positioned sub-forms to ensure that when text fields are set to expand, the expanded field doesn't overflow onto the other objects lower in your form. When using flowed sub-forms, you will also need to set your page to "flowed" for the object to work properly. I have done this in the example (note: setting a page to flow can have substantial unintended consequences in your layout - always save your form before you set page to flowed to enable you to go back). Wrapping other elements of your form in sub-forms, and setting that property to "Positioned" will help minimize this happenstance.
  6. I have assume your checkboxes represent mutually exclusive selections; in such instances, use a radio group which will prevent multiple selections. Use checkboxes if multiple selections are OK. You can make a radio group look like a checkbox with formatting properties.
  7. Normally if you use tables to display text fields, you drag a text field to a table row. the caption to the text field will disappear. The caption (or question) is normally placed in a table header row (you can set table rows to be either a header row or body row). See my example on page.

The link for the working code is found here: Dropbox - Untitled1.pdf

Good luck.

Avatar

Correct answer by
Level 4

Posted wrong file; use this link:

Dropbox - Untitled1RG.pdf