Conditionally enable string parameter

Is there a way to conditionally enable/disable a string input parameter? With the Active Choices plugin I see that selection inputs, like dropdowns, radio buttons, etc. can be controlled with arbitrary groovy code, but I need to control an input where user is permitted to enter any value.

Can anyone help me accomplish this?

Can you expound more on the purpose of doing this? Would a default value not work? What is the use case you are trying to solve (there might be a different way of accomplishing what you want to do).

Yes, hereā€™s the use case. I support a job for our development team to run validation tests in a ā€œnear productionā€ environment. There are two typical test suites, but sometimes a third option, for a user to type the name of a less-common test case, is needed. The dozens of options (even with a filter) in the drop-down isnā€™t practical, and I canā€™t know all the items in the list as recent checkins could have added/removed test cases. In summary, our users want this on the Build With Parameters page:

Input #1: Drop down
Test Class: MostCommonTestA (default), CommonTestB, OTHER

Input #2: Staring input, disabled unless Input #1 == OTHER
Enter Test Class:

What we have today is both inputs active. Often users enter something in Input#2, but forget to set Input#1 to ā€œOTHERā€, to prevent that mistake, weā€™d like to have Input#2 disabled until Input#1 has been set. I thought that Active Choice plugin could do this, but I donā€™t see how.

I think you would want an active choice reference parameter and return different input html depending on the drop down value. The active choice parameter plugin page has some examples of the reference parameter. So, since it is a reference parameter, you should have access to the current value of the drop down (also an active choice parameter) and be able to return different HTML based on the value (e.g., a hidden input element when a common test case is selected and a normal input text box when OTHER is selected).

1 Like

Thanks for the suggestions, I tried putting it in to practice, but I still must be missing something. Hereā€™s two attempts which seems close but still donā€™t work.

  • First one gives me an input box, but does NOT let me type in it!
  • Second displays the html input but doesnā€™t set the build parameterā€™s value with what I type. I tried wrapping the with various combinations of but always got same behaviour, not able to pass what I type to the value of the parameter.

Hereā€™s the two ā€œalmost solutionsā€, does anyone see what I might be missing??

Active Choices Reactive Reference Parameter:
Name: JUNIT_TEST_CLASS_OTHER1
Choice Type: Input Text Box
Referenced Parameter: JUNIT_TEST_CLASS

Groovy Script:
if (JUNIT_TEST_CLASS.equals(ā€œOtherā€)) {
return ā€˜Enter classname hereā€™
} else {
return ā€˜Disabledā€™
}
Result: Displays an input but will not let me type in it!

Active Choices Reactive Reference Parameter:
Name: JUNIT_TEST_CLASS_OTHER2
Choice Type: Formatted HTML

Groovy Script:
if (JUNIT_TEST_CLASS.equals(ā€œOtherā€)) {
return ā€œā€"

ā€œā€ā€œ;
} else {
return ā€œā€ā€Not activeā€œā€";
}
Result: Displays a text box, but does not send the contents to the build script, the parameter Iā€™m trying to set has empty value.

Your groovy needs to return an html with an suitably named input, see Active Choices

and more detailed here: Using Uno Choice for Dynamic Input Text Box Defaults Ā· biouno/uno-choice-plugin Wiki Ā· GitHub

1 Like