Remove an option from a select box field

Leandro Oliveir
Tera Contributor

Hi everyone,

 

I need to remove an option from a select box field in a catalog client script by using sys_choice table.

The current Client Script is this:

 

function onLoad() {
g_form.removeOption('what_do_you_want', 'seasonal_campaigns');
//Qual material?
g_form.removeOption('what_material', 'ear');
g_form.removeOption('what_material', 'gradio_banner');
g_form.removeOption('what_material', 'board');
g_form.removeOption('what_material', 'plastic');
}

 

It's working but I need to change this script by using the sys_choice table itself with the conditions for the reference field to read only the values ​​that apply to the field.

How to achieve this?

2 ACCEPTED SOLUTIONS

Harsh_Deep
Giga Sage

Hello @Leandro Oliveir 

 

Use select box and choose reference field as a choice table

Then add reference qualifier using script include.

 

That will work.

 

Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

Hi, 

Thanks for details, both the select box pointing to question_choice table where there is no dependency setup like sys_choice table. 

So first, create all qual material and qual problem label/value in Choice (sys_choice) table and setup dependency ( if applied ). 

second, re-configure both the catalog item variable with sys_choice table, after catalog form showing the data from sys_choice table then apply the removeOption logic.

 

As I understand , the qual problem depends upon qual material, so write a onChange client script on qual material field and apply removeOption base on matched condition.  

 

If( g_form.getValue("qual_material") == "putMatchedValueHere"){

g_form.removeOption("qual_problem" , "putTheRemoveValueHere" );

}

 

AshishKMishra_0-1697829873910.png

 

Let us know if it works for you or not. 

 

View solution in original post

8 REPLIES 8

AshishKM
Kilo Patron

Hi @Leandro Oliveir,

You can reference select box variable with sys_choice table, and use the onLoad() client script for conditional removeOption. 

 

 

 

if( referenceField == "value"){
 // apply the removeOption
g_form.removeOption("fieldName", "value");
}

 

 

 

 Please try with if condition and share the issue if any.

 

 

Harsh_Deep
Giga Sage

Hello @Leandro Oliveir 

 

Use select box and choose reference field as a choice table

Then add reference qualifier using script include.

 

That will work.

 

Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

 

Thanks

Leandro Oliveir
Tera Contributor

Can you give some example? I didn't understand very well.

Hi @Leandro Oliveir ,

Before we explain, can you share the detail of this select box , how is the current configuration. 

either this select box has its own "Question Choices" ( table : question_choice ) or its pointing to System Choice ( table : sys_choice ) 

 

So if you are using question_choice then configure the sys_choice table and add those choice values in the sys_choice table. once all choice options are displaying on form then apply this removeOption via the onLoad() for conditional removalOptions.

 

For more help, please share the current setup.