Questions related to prior choice value not disappearing when new choice is selected

Saquib Mohammed
Mega Guru

I have a scenario like this. 
Choice List 1 -> Outlook, Teams, etc

Choice List 2 (for outlook) -> choice1, choice2

Choice List 3 (for Teams) -> choiceA, choice B

When I select the different choices within the first level of choice list, e.g. If i switch between choice1 and choice2, the questions appear and hide the way they shoudl

When I select different choices on the first level of choice list, e.g. If I switch between Outlook and Team, then the questions from the previous selection do not disappear.

will I need to write a onChange client script and reload the form when election from first level of choice list changes? 

1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @Saquib Mohammed 

 

Have a look on the below example, you might be able to figure out the issue :

 

1. I have two variables, one for Tools with choices as Outlook and Teams and another for functionalities being offered by these tools where we will populate the choices dynamically based on the selection of tool.

AmitVerma_0-1716866848637.png

 

2. To populate the functionality choices, I have an On-Change Catalog Client Script being configured which will populate the choices based on change of tool. Observe that I am clearing the field options each time before populating the choices :

 

AmitVerma_1-1716866994288.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   g_form.clearOptions('function');
   if(newValue == 'outlook'){
	g_form.addOption('function','email','Email');
	g_form.addOption('function','meeting','Meeting');
   }
   else if(newValue == 'teams'){
	g_form.addOption('function','call','Call');
	g_form.addOption('function','chat','Chat');

   }
}

 

Result :

 

AmitVerma_2-1716867081659.png

 

AmitVerma_3-1716867104179.png

 

AmitVerma_4-1716867119495.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

Kavita_Bhojane
Tera Guru

Hi @Saquib Mohammed ,

 

Yes, you can make use of onChange client script to control visibility of questions.

You need to clear the choice field before hiding it. If it is mandatory field make it non-mandatory before hiding it.

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Kavita Bhojane

Anurag Tripathi
Mega Patron
Mega Patron

Hi Saquib,

These are a bit tedious to code,

But what I do is, on change of the field I first clear the dependent field altogether and then add what I want.

 

the g_form.clearOptions('<field name>') is what you are missing

 

-Anurag

Hi Anurag

I am not looking at removing the choice options. That part is working fine. I am looking to remove the questions when top level choice value changes. 

I was thinking of using onChange script with location.reload() method on the top level choice list variable. But it doesnt seem to work. Do you have any insight into that?

If you need to remove a question then you can just hide the question

g_form.setDisplay('<field name>', true);

Why do you need to reload the form?

-Anurag