How to hide a Drop-down (Choice list) when it's empty?

youming2007
Kilo Contributor

Hi ALL,

I have 2 drop-downs with a parent-child relationship:

  - Drop-down 1 is parent

  - Drop-down 2 is child (depends on Drop-down 1)

When parent's value is changed, child's values are populated automatically using Dictionary configuration (not Client Script).

Question 1:

  For example:

    Drop-down 1 has values: A, B and C

    When drop-down 1's value is set as A, drop-down 2 is populated with: -- None --, X and Y

    When drop-down 1's value is set as B, drop-down 2 is populated with: -- None -- and Z

    When drop-down 1's value is set as C, drop-down 2 is populated with: -- None -- only (NO value is set)

  When child is empty (only with -- None -- value), I want to hide child drop-down. Otherwise, I want to show it. Any ideas guys?

Question 2:

  When using both Dictionary configuration and Client script (Type = onChange) on the same drop-down, the execution order is Client script > Dictionary configuration.

  For example:

    Drop-down 1 has values: A, B and C

    When drop-down 1's value is set as A, drop-down 2 is populated with:

      - X, Y, Z by Dictionary configuration

      - X', Y', Z' by Client script

    => Client script is executed first, then Dictionary configuration. As a result, Drop-down 2 is populated with X, Y, Z

Can I switch or control the order of this behavior. I want Dictionary configuration is executed first, then Client script. Is it possible?

 

Many thanks,

 

13 REPLIES 13

The above script works for this. Have you tried it modifying the field names?

Ok, let me make it more clear.

find_real_file.png

Is this how you configured choices of child choice field in dictionary? If yes, modify the field names and labels and give a try with the above client script. It should work.

Otherwise, just share the screenshots of your dictionary and script that you have tried with. This helps.

Thanks

Hi archanareddy,

I understood your script. Here is my screenshot:

find_real_file.png

  Parent: Category (Value = -- None --, A and B)

  Child: [Criterion 1]

    - Value = -- None --, X and Y when parent = A

    - Value = -- None -- when parent = B

In both case, -- None -- is selected. So, based on your script, child is always hidden

However, I realized that onChange() on Child is called after Child is populated. It's what I'm looking for. Instead of checking newValue == '', I used control.options.length to determine if the control has only -- None -- value (length = 1).

Anyway, thanks for your help.

Thanks,

Client script will also work if you know which options of Parent field makes Child field options to only None

Anyways, glad you figured it out.