Conditional Visibility for Dynamic dialog based on Expression Methods

#1

Hi everybody,

I use some dynamics dropdown in my service dialogs based on Expression Method.

Is there a way to control visibility of the field for based expression methods dialog ?

For example, a checkbox with true/false displaying a text box or not.

I’ve already done that kind of things using Automate methods but I’d want to use the many advantages of the Expression Methods ( faster, RBAC, etc … ) for my dynamics dialogs.

Thanks !

#2

As far as I know Expression Methods to not support setting visibility. They support some parameters to customize their behaviour.

Given how dynamic dialog elements work with ruby methods, calling an Automate Instance, and reading the results from $evm.object I guess you can try this:

  • Create an Instance with 2 states. The first step is the expression method and the second step is a ruby method that only sets the visibility
  • Try to trick the code:
    • Create an Instance with two states as before

    • The first state is the normal expression method

    • The second state is an expression method with result_attr set to visible , set default_value to false and create an expression that returns something when the element should be visible and returns nothing if the element should be invisible.

      You can also try to get a true/false value using the attributes , result_type and/or result_obj parameters

With the first idea you will loose (some) of the speed expression methods have.
The second idea is very hacky, but I would be very curious if this actually works. We have the same use-case and I was planning on trying that, but haven’t had time yet

#3

Hi Buc,

Thanks for your reply. I’ve tried to implement your second idea because my goal was to only use Expression methods for my dialogs.

What I’ve wanted :
Have a dropdown with two values :

  • Create SSH key
  • Use existing key

When I choose Create SSH key, a textarea shows up to insert the nex key.
When I choose Use existing key, a dropdown show up to choose the known keypairs.

What I’ve done :

In my form, I have a true/false dropdown and two dynamics fields both hidden by default. In the Customization editor:

Capture%20d%E2%80%99%C3%A9cran%20du%202019-03-20%2012-19-55

Elsewhere in the form, I have a dropdown with my cloud providers and others fields ( like cloud tenant, etc … ).

I’ve created two instances for each dynamic dialog :

For the list_os_keypair, I’ve created those two Expression methods :
To list keypairs for selected cloud provider :

To set the visibility of the dropdown :

I test if the cloud provider status = value of my static dropdown ( true for Use Existing Keypair / false for Create New Keypair )

For the textarea visibilty, I’ve just use a NOT operator with the same expression :

And it works as I wanted ! :sunglasses:

When Use Existing Keypair is selected :

When Create a new keypair is selected :

Maybe it’s not the best or the more beautiful way to do it but it does the job ! With this solution, you need to test the true/false on an available resource.
I’ll try later to improve this to be smoother and easily reusable !

Thanks !

1 Like
#4

wow, I did not expect the second idea to actually work, but I am glad it is working for you :sunglasses:

And thanks for the great tutorial, I have to try that out at some point