Copy link to clipboard
Copied
Hello,
Need some help...I need to be able to hide several user input fields and some text fields when an option is selected from a drop down.
A few of the Fields to hide are
this.getField("CY CU").value // user entered field
this.getField("CY Plus CPI").value // user entered field
this.getField ("RY CU").value // user entered field
this.getField ("Expense type") // pre-filled text field that is read only is this still a .value
I tried the below as a validation on each of the user entered fields , but the problem was it didn't hide until user entered data. I don't want the user to enter data at all.
var drop = this.getField("Contract type").valueAsString;
if(drop == "2") event.target.display = display.visible;
else if (drop == "4") event.target.display = display.hidden;
So now, I'm wonder if I need to put the validation text on the drop down field, I'm assuming it will hide the field when the option is selected. But I'm not sure how I make the event.target all of those different fields if I put it there.
Any guidance would be helpful as I haven't found the other posts to be helpful.
Clueless beginner
In the Validation event, event.value doesn't return the Export Value, but the Display Value, so either adjust the code accordingly, or move it to the Calculation event. Also, you should tick the option to commit the field's selected value immediately (under Properties - Options), so that the script will execute as soon as you make a selection, not only when you exit the field.
Copy link to clipboard
Copied
Yes, you need to put the validation script onto the dropdown, because, it is the dropdown that is the source of the change that hides or shows fields.
Just as a general rule, when an action is driven from a single source, then the code that implements the action needs to be triggered by that source.
Of course your validation script will need to be changed because the "event" object will represent the dropdown.
var oFld = this.getField("CY CU");
if(event.value == "2") oFld.display = display.visible;
else if (event.value == "4") oFld.display = display.hidden;
// Then repeat for other fields.
Copy link to clipboard
Copied
You meant to write:
oFld.display = display.visible;
And:
oFld.display = display.hidden;
Copy link to clipboard
Copied
Still can't get it to work, even with the correction. Maybe some additional information will reveal something I'm missing. So regarding the drop down that is driving this the 2 and 4 are the export values I assigned to the items in the list.
The fields that I'm attempting to hide are currently formatted as visible. The field also has a custom format JavaScript.
I'm stumped and have been learning to write JavaScript as I go. This form is my most complex to date. And this is the last piece to figure out before I code the rest of the form. I appreciate the assistance and insight.
Copy link to clipboard
Copied
Are there any error messages when you use the script? Can you share the file in question with us?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
In the Validation event, event.value doesn't return the Export Value, but the Display Value, so either adjust the code accordingly, or move it to the Calculation event. Also, you should tick the option to commit the field's selected value immediately (under Properties - Options), so that the script will execute as soon as you make a selection, not only when you exit the field.
Copy link to clipboard
Copied
Okay. Ideally, I'll like to use the export value. I'm just not sure how to do that. I tried to get help with that a few weeks ago.
So I adjusted the code to the words in the drop down and moved it to the custom calucation script, but it still doens't hide the field. I need it to make the field "CY CU" not visible at all.
Again, I'm new at this. I'm getting better with each new challenge.
Copy link to clipboard
Copied
No, you have to do either one or the other. If you move the code to the Calculation event leave it as it was. If you edit it to have the Display Values, leave it under Validation. If you do both it still won't work...
Copy link to clipboard
Copied
Okay so I updated it under validation to the actual words and it still doesn't hide the field.
Copy link to clipboard
Copied
Finally got it work.
Copy link to clipboard
Copied