Adobe Interactive Forms. Part 23. How to Hide the Fields and Acquired Space Dynamically using JavaScript in Adobe Form
PREQ: Should be aware of basics of Adobe Form.
Transaction code: SFP
Enter the interface name and click on create.

Enter the description and save it.

Create the custom importing parameters variables by clicking the import button on the left side and click on create button on right side and save and activate it. We have declared three parameters of same type of CHAR20.

Now go back to the main screen of SFP and choose the option Form and create it by adding the interface which we had created previously.
On the left side expand import section of interface and drag and drop all the importing variables IV_NAME1, IV_NAME2 and IV_NAME3 to context.

Let’s create the Layout of form which is available next to Context button.
Switch to design view and click on Hierarchy part. Select the content area of a form and click on object (right side) after that click on Subform and choose content type: Flowed

Now here we will design the form using Subform and wrap every object like text fields, text box, Buttons and tables etc. in it.
Here we will create 4 Subforms in content area.
Now select the Subform and inert the text fields and rename the default name of Text Fields to:
Name1, Name2 and Name3

Do the binding of all three text fields from the importing parameter variables (IV_NAME1, IV_NAME2 and IV_NAME3) by clicking on the the binding > Data Binding > choose the field

After the we will hide the field Name2 of subform2 using JavaScript. Select the subform2 and go to Palettes > Script Editor

You will get the below screen

Choose the event Initialize and language JavaScript and write the below code.
if( this.Name2.rawValue == null )
{ this.presence = ‘hidden’
}
We are hiding the field Name2 if its empty.

Always use the same field name (Name2) in script which is defined in the subform and it’s a case sensitive also otherwise it won’t work.
Check save and activate it.
Let’s test our form.
Case 1: Press F8 and pass all the importing values.

Press F8 and press on print preview.

Here script won’t hide Name2 as have passed the value in IV_NAME2.
Case 2: IV_NAME2 = ‘ ‘.
Press F8 and don’t pass the value in IV_NAME2.

This time JavaScript code gets executed to hide the field Name2 and removed the space also.
If you see below fields has shifted to up and adjusted the space automatically. This is only possible if you wrap the fields in Subform.

Hope you were able to get a fair idea about this interesting topic. If you have any doubts, queries or suggestions for us, please put your comments below. I will be happy to respond you.
YOU MAY LIKE THIS
SAP ABAP Checkpoint Group – Chase the Mysterious SAP Issues with a Smile
Best Practices for SAP ABAP Development: A Comprehensive Guide