Hiding field value dependent on another field value

jas101
Tera Expert

Hi guys,

 

I have created a UI policy to hide (stop a value from being selected) on a field called 'Subtype' e.g. value 'Minor' when the value of 'Domain' field is e.g. 'Deacons' - while this works if the Domain chosen initially is 'Deacons' if it is then changed, the 'Minor' Subtype value is still unselectable (when it should be selectable). Likewise if I choose another Domain initially and set the Subtype as 'Minor' I can then change the Domain value to 'Deacons' - meaning the Subtype value which should not be selectable is!

ui policy hiding minor subtype.PNG

 

I think this is because I have it onLoad in the UI Policy - in which case I need it more dynamic, i.e. whenever the value of Domain field changes, do I therefore need a client script instead?

 

Another option would be to force the value of Subtype to always be 'Standard' when the Domain is 'Deacons' but I'm unsure what is easier.

 

Any/all help much appreciated as always.


Cheers,

Daniel

1 ACCEPTED SOLUTION

whatever value you want to set use the below line in 'execute if true' and 'execute if false' section,



g_form.setValue('subtypeVariableName','whateverValueNeeded');



place this as the last line in the corresponding sections


View solution in original post

15 REPLIES 15

randrews
Tera Guru

I don't like using remove option because of this very issue... once it is removed it isn't ever put back and it causes the selections to behave in an unexpected manner when the customer starts flip flopping selections...



there are three ways to handle this and which you choose depends on how many options you have to change...



1> create multiple variables... so you can have a sub type for everything BUT minor and a sub_type for minor...


2> do it in a script the way you are .. except instead of using a remove option.. start by clearing all optiions with a g_form.ClearOptions, then write if scripts below it that will add values to the drop down based on the selection made <so rebuild the list everytime they change the first selection> ensure   that ALL options you include in the addOptions are in the selecttion for the field or it won't appear right after the form is filled out.


3> base the selection box off of it's own table... so you would have a sub_type table with check boxes for each type.. and put a reference qualifier that limits the sub type based on the type.


Thanks Doug. Are you to able to expand on the scripting required please? Would I still be using a UI Policy? Just to clarify further:



All Domains should see all Types (i.e. Planned, Routine, Emergency).



Subtypes are dependent on Types. (i.e. Standard and Minor for Planned, 20+ options for Routine and 5 for Emergency).



All options should be visible with the one exception that when 'Deacons' is selected for Domain, Subtype 'Minor' should not be selectable.



Many thanks.


Daniel


i say use whatever you have already and add a little tweak



kepp the script as is and put this in 'execute if false'



g_form.removeOption('change_request.u_sub_type','Minor');


g_form.addOption('change_request.u_sub_type','Minor','Minor');



Hope this works for you


Thanks Kalai, but while Minor is hidden if Deacons is selected, Minor is still greyed out if I then change the Domain to another where Minor should be selectable.