repeatable with selector and items to be hidden or visible on selection

71 views
Skip to first unread message

Cinemo IT

unread,
Nov 29, 2023, 7:32:36 AM11/29/23
to Jenkins Developers
Hi, 

I'm trying to create a plugin with configuration in the jenkins manage system. 

When i tried to use global.jelly it always complained, and wanted to have config.jelly so i always use config.jelly online now. 

Anyway, basically i want to have a repeatable with add button that has a drop down menu for example with set of selections, once a selection is made a few other fields should either show up or get invisible, and on save and reload for config page it should have the items I've selected earlier to be preloaded.


Here is example of the jelly that i've created:

<f:entry title="Optional Fields">
    <f:repeatable var="optionalField" items="${instance.optionalFields}" name="optionalFields" varStatus="status">
        <script>
            document.getElementById('selector${status.index}').onchange = function() {
                var selectedValue = this.value;
                var repeatableFields = document.selectedValue("repeatable-fields_${status.index}");
                for (var i = 0; i &lt; repeatableFields.length; i++) {
                    if (selectedValue !== "" &amp;&amp; parseInt(selectedValue) &gt; 1) {
                        repeatableFields[i].style.display = 'block'; // Show the repeatable fields
                    } else {
                        repeatableFields[i].style.display = 'none'; // Hide the repeatable fields
                    }
                }
            };
        </script>

        <f:entry title="">
          <div align="right">
            <f:repeatableDeleteButton />
          </div>
        </f:entry>
         <f:entry title="Select Option" field="selectedValue">
           <select name="selectedValue" id="myDropdown${status.index + 1}" class="jenkins-select__input select">
            <option value="0">Select an option</option>
            <option value="1">Freestyle</option>
            <option value="2">Pipeline</option>
            <option value="3">Multibranch</option>
            <option value="4">Oragnization</option>
          </select>
        </f:entry>
        <div id="repeatable-fields_${status.index}" data-option="pipelinejobs" style="display: none;">
          <f:entry title="field1" help="">
            <f:textbox name="field1" value="${optionalField.field1}" title="Field 1" />
          </f:entry>
          <f:entry title="field2" help="">
            <f:textbox name="field2"  value="${optionalField.field2}" title="Field 2" />
          </f:entry>
          <f:entry title="field3" help="">
            <f:textbox name="field3"  value="${optionalField.field3}" title="Field 1"  />
          </f:entry>
          <f:checkbox name="scriptedPipeline" title="Script pipeline enabled" class="hidden-checkbox" />
          <f:checkbox name="enableScm" title="Scm enabled" class="hidden-checkbox" />
        </div>
        <f:checkbox id="failBuild${status.index + 1}" name="failBuild" title="Fail Build" />
    </f:repeatable>


So first of all the varStatus doesn't really change and it is kind of sticky to 1 always, also when loading page it gets null. 

Just loading the configuration page gives this 
image1.png

Trying to add an item would show this 
image2.png
The selection items are really there however when selecting any nothing change. I've tried to also use onChange to use a function in the select tag but still was not sending the status correctly. 

Is this the correct way of doing it? Or there is another way. 

Also the reloading of page the previous selected item isn't loaaded again even if the selection value was saved on disk correctly.

Jesse Glick

unread,
Nov 29, 2023, 1:19:49 PM11/29/23
to jenkin...@googlegroups.com
On Wed, Nov 29, 2023 at 7:32 AM Cinemo IT <cine...@gmail.com> wrote:
Anyway, basically i want to have a repeatable with add button that has a drop down menu for example with set of selections, once a selection is made a few other fields should either show up or get invisible, and on save and reload for config page it should have the items I've selected earlier to be preloaded.

Nothing of this kind is supported by the Jenkins configuration form framework. Try a simpler and more standard UX.
Reply all
Reply to author
Forward
0 new messages