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:
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:
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