The CreatorCon Call for Content is officially open! Get started here.

How to hide Choice options without removing them

ritaaudi
Tera Contributor

Hi: I want to be able to hide some Choice entries but not remove them, so that they can be updated by business rules but prevent the user from selecting them. Is there a way to do this? I know you can use g_form.removeOption(<field>, <choice>). I guess I am looking for a g_form.hideOption(<field>, <choice>), but that doesn't work.

Thanks for your help!

Rita

1 ACCEPTED SOLUTION

Sure Rita.



Just to give you another option-


"g_form.removeOption(<field>, <choice>) did not work for me because when I set the removed choice using the business rule, the removed choice did not appear on the form."


To show the removed choice when it is set by business rule you can add condition to the onLoad client script/UI action(containing removeOption()) to check if the current choice is not the one to be removed and if it not then remove the option.


For e.g. lets say you don't want to allow the users to select state1.


Then you can add condition - State is not state1 - and in script 'g_form.removeOption('state','state1');'.


This will remove the option only if it is not currently set on the record. If its set then it will be displayed else it will be removed. If you again set it to any other state again it will be removed.



--Mark correct/helpful if it helps solving your issue.


View solution in original post

12 REPLIES 12

Hi Tanaji: I like your suggestion. That will work for me too!


Thanks, Rita


Thank you Tanaji 🙂 It worked....!!!!

Edvin-Karalius
Tera Guru

I know this is a super old post, but I was looking for a solution to hide options without removing them.
Didn't find anything so I created my own. This solution is simple and allows you to hide choice elements but still allowing them to be set as proper values with displayValues by server-side scripts.

So this client script sets the options to be hidden but still usable by server side scripts.

function onLoad() {
   var options= Array.from(g_form.getControl('YOUR_FIELD_NAME')); //Set your target field
   var hiddenOptions = ['option_1', 'option_2']; //Add your choice values to hide here.

   options.forEach(function(e){
	if(hiddenOptions.indexOf(e.value) > -1)
		e.hidden = true;
   });
}


Example:

EdvinKaralius_0-1693151806330.png

 

This worked beautifully.  Straight forward and easy to implement.  Thank you very much!

Hi I have similar requirement 
i want to hide "on hold" choice in state field in incident form based on the "Platform" field entries so i want to hide "on hold" choice when the platform team is uv , hcl and av team . so for these teams on hold choice should be hidden in state field 
can you suggest me on how to achieve this