Parameter definition with cascading selection

23 views
Skip to first unread message

Andrew Sumner

unread,
Jan 1, 2020, 6:20:31 AM1/1/20
to Jenkins Developers
A parameter that I am developing for my plugin requires two select fields, the second one being populated using the value selected from the dropdown list of the first field. My problem is that I don't know how to repopulate the list for the second field.

I've got as far as detecting the change in the first field but I don't know how to force a refresh of the second field;

ParameterDefinition - index.jelly

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
   
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
   
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">


   
<j:set var="escapeEntryTitleAndDescription" value="false"/>
   
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
   
<div name="parameter">
     
<input type="hidden" name="name" value="${it.name}" />


     
<select name="applicationId" onchange="alert('what do I do here?');">
         
<j:forEach var="item" items="${it.applications}">
           
<option value="${item.value}">${item.name}</option>
         
</j:forEach>
     
</select>


     
<select name="releaseNumber">
         
<j:forEach var="item" items="${it.releases}">
           
<option value="${item.value}">${item.name}</option>
         
</j:forEach>
     
</select>
   
</div>
   
</f:entry>
</j:jelly>


I'm also wondering if this is the best approach. I could potentially split this out into two seperate fields, however I then need to replicate the behaviour of the active choices plugin and that sounds a bit daunting...

Any suggestions?

Andrew Sumner

unread,
Jan 4, 2020, 3:22:37 AM1/4/20
to Jenkins Developers
I've tried using <st:adjunct include="org.kohsuke.stapler.jquery"/> to add jQuery support and trialled it out using jQuery('div[name="parameter"]') but getting error jQuery is not a function.

  1. How should I add jquery?
  2. How to I use it do call back to parameter definition class get updated list for second dropdown?

Gavin Mogan

unread,
Jan 4, 2020, 3:29:56 AM1/4/20
to jenkin...@googlegroups.com
I can't help with the adjunct (Did you add it as a dependency?)

But you can do the selector pretty easily in your browser and not need jquery


document.querySelector('div[name="parameter"]').value should work in almost all browsers that are not ie9

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2105b7ad-a832-42f2-a124-9f64c0a5d60c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages