Skip to content

Commit

Permalink
Add combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Dec 16, 2024
1 parent 4688664 commit 9e182be
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/io/jenkins/plugins/designlibrary/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hudson.model.AutoCompletionCandidates;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.util.ComboBoxModel;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -52,6 +53,10 @@ public ListBoxModel doFillStateItems() {
return m;
}

public ComboBoxModel doFillState2Items() {
return new ComboBoxModel(STATES);
}

public ListBoxModel doFillCityItems(@QueryParameter String state) {
ListBoxModel m = new ListBoxModel();
for (String s : asList("X", "Y", "Z")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ THE SOFTWARE.
</s:section>

<s:section title="${%searchable}" description="${%searchable.description}">
<div class="jenkins-paragraph">${%combobox}</div>

<s:group>
<s:preview>
<form>
<button type="submit" disabled="true" style="display: none" aria-hidden="true"/>
<f:entry title="U.S. State" field="state2">
<f:combobox/>
</f:entry>
</form>
</s:preview>
<s:code-panes>
<s:code-pane title="Jelly">
<s:code file="combobox.jelly"/>
</s:code-pane>
<s:code-pane title="Java">
<s:code file="Combobox.java" language="java"/>
</s:code-pane>
</s:code-panes>
</s:group>

<div class="jenkins-paragraph">${%textbox}</div>

<s:group>
<s:preview>
<f:entry title="U.S. State" field="state">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ usage.2=If you want a simpler <code>select</code> to be rendered you can use the
Jelly tag and create a <code>doFillFieldNameItems</code> method in the <code>descriptor</code>.
dynamic=Dynamic select
dynamic.description=Updates the contents of a "select" control dynamically based on selections of other controls.
searchable=Searchable select
searchable=Autocomplete
searchable.description=Allows users to quickly browse a select by typing to filter the available choices. Start typing a U.S. state for results to appear.
combobox=Using <code>combobox</code> forces the user to select an option from the available choices, it''ll also display all choices on focus.
textbox=Using <code>textbox</code> on the other hand allows the user to enter free text if they so desire.
10 changes: 10 additions & 0 deletions src/main/webapp/Select/Combobox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Sample {
private static final String[] STATES = new String[]{
"Alabama",
"..."
};

public ComboBoxModel doFillStateItems() {
return new ComboBoxModel(STATES);
}
}
3 changes: 3 additions & 0 deletions src/main/webapp/Select/combobox.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<f:entry title="U.S. State" field="state">
<f:combobox />
</f:entry>

0 comments on commit 9e182be

Please sign in to comment.