Skip to content

Commit

Permalink
Add random IDs for radio
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 27, 2022
1 parent fa263e7 commit d56150d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2289,4 +2289,9 @@ public static boolean isContextMenuVisible(Action a) {
return true;
}
}

@Restricted(NoExternalUse.class)
public static String generateItemId(String id) {
return Math.floor(Math.random() * 3000) + "-" + id;
}
}
5 changes: 3 additions & 2 deletions core/src/main/resources/lib/form/radio.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ THE SOFTWARE.
toggles the radio.
</st:attribute>
</st:documentation>
<j:set var="itemId" value="${h.generateItemId(id)}" />
<div class="jenkins-radio">
<input class="jenkins-radio__input" type="radio" name="${attrs.name}" onclick="${attrs.onclick}"
id="${attrs.id}" value="${attrs.value}" checked="${attrs.checked?'true':null}"
id="${itemId}" value="${attrs.value}" checked="${attrs.checked?'true':null}"
disabled="${readOnlyMode?'true':null}" />
<label class="jenkins-radio__label ${attrs.id != null ? '' : 'attach-previous'}" for="${attrs.id}">${attrs.title}</label>
<label class="jenkins-radio__label" for="${itemId}">${attrs.title}</label>
<div class="jenkins-radio__children">
<d:invokeBody />
</div>
Expand Down

0 comments on commit d56150d

Please sign in to comment.