Cascading options - Entirely remove/show option based on previously selected values

1,071 views
Skip to first unread message

Dávid Matušík

unread,
Jul 31, 2019, 8:25:48 AM7/31/19
to rundeck-discuss
Hi,

I'm using cascading options and I would like to know if it's possible to remove / show options based on selection from previous option

For example:

Input option1 has values A or B
if value A is selected there are input option2 and option3 presented to user

if option1 value B is selected, there will be only input option3 available and option2 is hidden


If it's possible, could I get working example ?

Reiner Acuña

unread,
Jul 31, 2019, 2:27:50 PM7/31/19
to rundeck-discuss
Hi David,

You can set different options in JSON files for each values like this:

services.json:

[
{"name":"Audio Services", "value":"audio.json"},
{"name":"Video Services", "value":"video.json"}
]

audio.json:

[
{"name":"lastfm", "value":"Last.fm"},
{"name":"tunein", "value":"TuneIn"}
]

video.json:

[
{"name":"youtube", "value":"Youtube"},
{"name":"dailymotion", "value":"Dailymotion"}
]

And here the job definition, check the "valuesUrl" of option2:

<joblist>
<job>
<context>
<options preserveOrder='true'>
<option enforcedvalues='true' name='option1' required='true' valuesUrl='file:/home/m68k/Rundeck/ver/3.0.24/projects/ProjectCASCADE/services.json' />
<option enforcedvalues='true' name='option2' valuesUrl='file:/home/m68k/Rundeck/ver/3.0.24/projects/ProjectCASCADE/${option.option1.value}' />
</options>
</context>
<defaultTab>summary</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>3134efd6-050a-47fb-b64e-2a66862e0b75</id>
<loglevel>INFO</loglevel>
<name>JobCASCADE</name>
<nodeFilterEditable>false</nodeFilterEditable>
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>echo "The selected service is: ${option.option2}"</exec>
</command>
</sequence>
<uuid>3134efd6-050a-47fb-b64e-2a66862e0b75</uuid>
</job>
</joblist>

Regards!

Dávid Matušík

unread,
Aug 2, 2019, 4:37:42 AM8/2/19
to rundeck-discuss
Hello Reiner,

This only dynamically changes the values, as I stated I'm already using cascading options. 
My question is if we can hide / show an OPTION itself - example: There are 3 options if I select A, there are only 2 options if I select B (not option VALUES, but OPTION as a whole)

Thanks

Regards,
David

Dňa streda, 31. júla 2019 20:27:50 UTC+2 Reiner Acuña napísal(-a):
Message has been deleted
Message has been deleted
Message has been deleted

Reiner Acuña

unread,
Aug 2, 2019, 2:21:34 PM8/2/19
to rundeck...@googlegroups.com
Hi David,

For that you need to check that to create UI plugins focused on your jobs:

https://docs.rundeck.com/docs/developer/ui-plugins.html

You have a good UI plugin example here:

https://github.com/rundeck-plugins/ui-plugin-examples

I leave this plugin example:


For this Job Definition:

<joblist>
<job>
<context>
<options preserveOrder='true'>
<option enforcedvalues='true' name='option1' required='true' valuesUrl='file:/home/user/Rundeck/ver/3.0.22/projects/ProjectCASCADE/services.json'>
<label>option1</label>
</option>
<option enforcedvalues='true' name='option2' valuesUrl='file:/home/user/Rundeck/ver/3.0.22/projects/ProjectCASCADE/${option.option1.value}'>
<label>option2</label>
</option>
<option name='texto'>
<label>texto</label>
</option>
</options>
</context>
<defaultTab>summary</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>3134efd6-050a-47fb-b64e-2a66862e0b75</id>
<loglevel>INFO</loglevel>
<name>JobCASCADE</name>
<nodeFilterEditable>false</nodeFilterEditable>
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>echo "The selected service is: ${option.option2}"</exec>
</command>
</sequence>
<uuid>3134efd6-050a-47fb-b64e-2a66862e0b75</uuid>
</job>
</joblist>

And these JSON files:

services.json:

[
{"name":"Audio Services", "value":"audio.json"},
{"name":"Video Services", "value":"video.json"}
]

audio.json:

[
{"name":"lastfm", "value":"Last.fm"},
{"name":"tunein", "value":"TuneIn"}
]

video.json:

[
{"name":"youtube", "value":"Youtube"},
{"name":"dailymotion", "value":"Dailymotion"}
]


The key of that plugin is the file "main.js" (at /resources/js inside the zip file) you can see a javascript function that "hide" a textbox based on your selection. Feel free to use an modify it.

Hope it helps!


--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/b1d50920-9334-4b77-b738-ab7c924d30cc%40googlegroups.com.


--
Reiner Acuña Pisani
IT Support
Rundeck

Dávid Matušík

unread,
Aug 7, 2019, 11:42:00 AM8/7/19
to rundeck-discuss
Thanks Reiner,

After some modification this plugin works perfectly for me.

Cheers,
David

Dňa piatok, 2. augusta 2019 20:21:34 UTC+2 Reiner Acuña napísal(-a):
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck...@googlegroups.com.

albert trebla

unread,
Oct 6, 2023, 8:45:48 AM10/6/23
to rundeck-discuss
Hi Reiner, Hi David

First of all, thank you for your contribution

I know it's been a long time since this post but I hope you can help me.

Basically I have the same problem as David, that is, showing or hiding an option (the entire field) depending on the value of another.
I also read that David solved the problem thanks to your help.
Unfortunately I can't make the plugin work that I downloaded from here: https://github.com/MegaDrive68k/plugins/blob/master/option-filter.zip and copied to /var/lib/rundeck/libext with the job definition of your message.
Could you kindly provide me with some further explanation?

Unfortunately I'm not very familiar with rundeck and I'm not understanding a few things.
In particular:

1) in main.js I find this:

  var rootOption = 'family';
 var childOption = 'ssh_usr';
 var hideValue = 'windows.json';  

But in the job definition of JobCASCADE that you attached here,  i don't find neither "family" nor "ssh_usr" nor the remote file named "windows.json".
I see these files:  "services.json", "audio.json" and "video.json". 
What is "windows.json"?
Sorry but i'm very confused.

2) once the zip of the rundeck plugin has been copied, it needs a reboot to see it?

It's clear that I'm not understanding many things. 
I would be really grateful if you could provide me with a little explanation so I can make this thing work.


Thanks in advance for any help you can.
Albert

albert trebla

unread,
Oct 6, 2023, 8:45:48 AM10/6/23
to rundeck-discuss
Hi Reiner,


First of all, thank you for your contribution

I know it's been a long time since this post but I hope you can help me.

Basically I have the same problem as David, that is, showing or hiding an option (the entire field) depending on the value of another.
I also read that David solved the problem thanks to your help.
Unfortunately I can't make the plugin work that I downloaded from here: https://github.com/MegaDrive68k/plugins/blob/master/option-filter.zip and copied to /var/lib/rundeck/libext with the job definition of your message.
Could you kindly provide me with some further explanation?

Unfortunately I'm not very familiar with rundeck and I'm not understanding a few things.
In particular:

1) in main.js I find this:

> var rootOption = 'family';
> var childOption = 'ssh_usr';
> var hideValue = 'windows.json';


But in the job definition of JobCASCADE, you attached there, i don't find neither "family" nor "ssh_usr" nor the remote file named "windows.json"
I see "services.json", "audio.json" and "video.json". What is "windows.json"?
Sorry but i'm very confused.

2) once the zip of the rundeck plugin has been copied, it needs a reboot to see it?

I would be really grateful if you could provide me with a little explanation so I can make this thing work.

Thanks for your kindness

Thanks in advance
Albert


Il giorno venerdì 2 agosto 2019 alle 20:21:34 UTC+2 rac...@rundeck.com ha scritto:

rac...@rundeck.com

unread,
Oct 6, 2023, 2:09:48 PM10/6/23
to rundeck-discuss

Hi Albert, sure.

I think that I changed the plugin to focus on another example. but I finally tried the plugin after many years (it was difficult to recall how the code works, but it was a good challenge). Let’s start.

On Rundeck, I have this job definition with two options:

- defaultTab: nodes description: '' executionEnabled: true id: 3134efd6-050a-47fb-b64e-2a66862e0b75 loglevel: INFO name: JobCASCADE nodeFilterEditable: false options: - enforced: true name: option1 required: true valuesUrl: file:/my/path/toos.json - enforced: true name: option2 valuesUrl: file:/my/path/to/${option.option1.value} plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - exec: 'echo "The selected server is: ${option.option2}"' keepgoing: false strategy: node-first uuid: 3134efd6-050a-47fb-b64e-2a66862e0b75

This plugin needs three JSON files as remote options:

os.json

[ {"name":"windows", "value":"windows.json"}, {"name":"linux", "value":"linux.json"} ]

windows.json

[ {"name":"AD_Server", "value":"ad_server"}, {"name":"SQLServer", "value":"sql_server"} ]

linux.json

[ {"name":"k8s", "value":"K8S"}, {"name":"ssh", "value":"SSH"} ]

Now, let’s see the plugin code (option-filter.zip) I changed only the ‘ main.js’ file:

function initJobFilter() { //console.log(rundeckPage.path()); if(rundeckPage.path() === "scheduledExecution/show"){ var checkExist = setInterval(function() { if (jQuery('[name="extra.option.'+rootOption+'"]').length) { clearInterval(checkExist); filterSSHUSR(); jQuery('[name="extra.option.'+rootOption+'"]')[0].setAttribute("onchange", "filterSSHUSR()"); } }, 100); } } var rootOption = 'option1'; var childOption = 'option2'; var hideValue = 'linux.json'; function filterSSHUSR(){ if(jQuery('[name="extra.option.'+childOption+'"]').size()==1){ var input1 = jQuery('[name="extra.option.'+childOption+'"]')[0]; if(jQuery('[name="extra.option.'+rootOption+'"]')[0].value==hideValue){ jQuery(input1).closest('.form-group')[0].hidden=true; }else{ jQuery(input1).closest('.form-group')[0].hidden=false; } } }

Now, how it works?

The idea is that if you select “Linux” in the first option, the second option should be removed. However, if you select “Windows,” you will be presented with the second choice, which includes two Windows Servers. Great but…

The problem here is that this type of plugin does not work on the most recent Rundeck version (I tested on 3.0.22 vs 4.17). It is still operational on 3.0.22). This is due to the significant difference in graphic internal library modifications between Rundeck 3.0.X (2017) and the most recent Rundeck version.

So, please, open a new ticket here to request this compatibility back again.

Thanks!

albert trebla

unread,
Oct 9, 2023, 4:35:01 AM10/9/23
to rundeck-discuss
Hi Reiner

Thank you very much for this answer and for the time you dedicated to it. 
Your work was truly precious to me.

Regarding the problem of the graphics library on new versions, I am on version 4.3 and I imagine that this solution does not work and neither does the example shown here: https://github.com/rundeck-plugins/ui-plugin-examples.

So on versions after 3.0.22 there is no way to make a UI plugin work? 
There is no working example?

Many thanks again for your precious help

Albert

rac...@rundeck.com

unread,
Oct 10, 2023, 8:07:51 AM10/10/23
to rundeck-discuss
Hi Albert,

Thanks! I remember that after Rundeck 3.3.X this capability stopped working. So, it works on Rundeck 3.1 and 3.2.

Regards.
Reply all
Reply to author
Forward
0 new messages