Skip to main content
Question

Hide and show multiple fields on a form based on conditions using Java Script.

  • May 10, 2019
  • 0 replies
  • 150 views

Below is my scenario:
I have 2 tables Course and Enrollment. 
Course table contains Course name, number of activities, assessment method(total 10 text fields) and course description. 
Enrollment contains 2 Pass or fail field (dropdown) and a date field for one assessment method field. 
So for every Assessment method field there are 2 passfail and date fields. (total 20)

Enrollment and course are connected in such a way that many enrollments belong to one course. 

I need to show or hide these pass fail and date fields based on number of activities field in course. When a course name is selected from a drop down, number of activities is also displayed as a lookup field. 

Example: for number of activities =3 
show Assesment method 1 , 2 and 3 
show pass fail 1 ,2,3,4,5 and 6
show date 1 ,2,3,4,5 and 6
hide assessment method 4 to 10
hide pass fail 7 to 20 
hide date 7 to 20. 

Can anyone please help to resolve this?

This sounds like you want to use Dynamic Form Rules.  You will make a separate Dynamic Form rule for every field or every set of fields (or sections(s)) which are to behave identically.

ie you need to look at any given field and make a single rule to either show or hide that field.

  • Registered
  • May 10, 2019
Is there a reason you are wanting to use JavaScript for this? I was sitting here trying to visualize this and came to the same conclusion as Mark. It seems like form rules would work great and be a simpler way to accomplish this.

  • Author
  • Registered
  • May 10, 2019
The form rules don't work as there are hide and show constraints on same fields based on different number of activities. For example:

If number of activites =2 
show assesment method 1 and 2
hide assessment menthod 3 to 10 
show date 1 to 4
hide date 5 to 20
show pass fail 1to 4
hide pass fail 5 to 20

if number of activities = 3
show assessment method 1,2 and 3
hide assessment method 4 to 10
show date 1 to 6
hide date 7 to 20
show pass fail 1 to 6
hide pass fail 7 to 20. 

this creates show/hide conflicts on passfail and date fields. 

No problem to use formula fields.  For example make a formula field checkbox called 

[Show Field 1?] and define the formula for when to show Field 1.

Then have a Dynamic Form rule that is super easy

When
[Show Field 1] is checked

Action
Show [Field 1]


  • Author
  • Registered
  • May 10, 2019
Can you give me an example using my scenario? 

You could use 20 formula checkbox fields.

The formula for [Show Assessment method 1]

would be

IF([# of activities]=3, true)