Skip to main content
Participating Frequently
January 8, 2022
Answered

Hide/unhide form field based on other form text field is empty or not

  • January 8, 2022
  • 1 reply
  • 3827 views

Hello.

 

I am not really good with javascrip. How can I solve that I like to make a form text field only visible if the previous form text field is filled. Thanks

This topic has been closed for replies.
Correct answer Nesa Nurani

It's possible but you will have to enter script into each field.

You will use scripts as 'custom keystroke script'.

Go to field properties -> format tab and select 'custom' then 'custom keystroke script' (when you enter script it will disappear but it will still work).

for row1:

put this in "ItemName1" field:

this.getField("MaterialNumber1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

put this in "MaterialNumber1" field:

this.getField("ItemQuantity1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

 

Repeat for other rows by changing field names in script.

1 reply

Nesa Nurani
Community Expert
January 8, 2022

Since you didn't provide field names lets say you have "Field1" and "Field2", to hide/show "Field2" depending on "Field1" value, as validation script of "Field1" use this:

this.getField("Field2").display = event.value == "" ? display.hidden : display.visible;

Participating Frequently
January 8, 2022

Thank you Nena. Can It be triggered by the start of the typing and dynamic (I mean If i clear the first field in the case the second field become invisible)? There are 3 colomns and 15 rows. Only the first row is visible and i like to make visible every colomns in the following rows after start the typing in the previous. The Field names ItemName1-ItemName15/SKU1-SKU15/Quantity1-Quantity15  and the order in the ItemName->SKU->Quantity. I know the Quantity in the row validate the ItemName in the next row. With the above script it is working but isn't hide the next field if I empty the previous (I like to do it in the case both are empty). 

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
January 9, 2022

It's possible but you will have to enter script into each field.

You will use scripts as 'custom keystroke script'.

Go to field properties -> format tab and select 'custom' then 'custom keystroke script' (when you enter script it will disappear but it will still work).

for row1:

put this in "ItemName1" field:

this.getField("MaterialNumber1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

put this in "MaterialNumber1" field:

this.getField("ItemQuantity1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

 

Repeat for other rows by changing field names in script.