Reproduction
Code in Jelly
<f:entry title="${%Test select}" field="testSelect"> <f:select/> </f:entry>
Code in Java
// in Describable private String testSelect; public String getTestSelect() { return testSelect; } @DataBoundSetter public void setTestSelect(String testSelect) { this.testSelect = testSelect; } // [...] // in Descriptor public ListBoxModel doFillTestSelectItems(@QueryParameter String testSelect){ ListBoxModel items = new ListBoxModel(); items.add(new ListBoxModel.Option("- none -", "", testSelect.isBlank())); items.add(new ListBoxModel.Option("Test 1", "test1", testSelect.equals("test1"))); items.add(new ListBoxModel.Option("Test 2", "test2", testSelect.equals("test2"))); items.add(new ListBoxModel.Option("Test 3", "test3", testSelect.equals("test3"))); return items; }
Scenario preparation
- Open the form
- "- none -" is selected
- Select test2
- "test2" is now selected
- Save and come back OR apply and refresh
- "test2" is still selected
- Select test3
- "test3" is now selected
- Save and come back OR apply and refresh
- "test3" is still selected
- [Now the bug, see attached gif]
- Select "- none -"
- (2 rounds of doFill)
- "test2" is now selected
- Re-select "- none -"
- (1 round of doFill, as usual)
- This time it's working, "- none -" is now selected
It seems due to the special logic included in refillOnChange.
Note: Even if it's especially visible when playing with credentials and the includeEmptyValue() method, the behavior is coming from f:select.
[JENKINS-73518] j:select does not like empty values
Description |
Original:
h3. Reproduction
Code in Jelly {code:java} <f:entry title="${%Test select}" field="testSelect"> <f:select/> </f:entry> {code} Code in Java {code:java} // in Describable private String testSelect; public String getTestSelect() { return testSelect; } @DataBoundSetter public void setTestSelect(String testSelect) { this.testSelect = testSelect; } // [...] // in Descriptor public ListBoxModel doFillTestSelectItems(@QueryParameter String testSelect){ ListBoxModel items = new ListBoxModel(); items.add(new ListBoxModel.Option("- none -", "", testSelect.isBlank())); items.add(new ListBoxModel.Option("Test 1", "test1", testSelect.equals("test1"))); items.add(new ListBoxModel.Option("Test 2", "test2", testSelect.equals("test2"))); items.add(new ListBoxModel.Option("Test 3", "test3", testSelect.equals("test3"))); return items; } {code} h4. Scenario preparation * Open the form * "- none -" is selected * Select test2 * "test2" is now selected * Save and come back OR apply and refresh * "test2" is still selected * Select test3 * "test3" is now selected * Save and come back OR apply and refresh * "test3" is still selected * *[Now the bug, see attached !bug_select_empty.gif! gif]* * Select "- none -" * (2 rounds of doFill) * "test2" is now selected * Re-select "- none -" * (1 round of doFill, as usual) * This time it's working, "- none -" is now selected It seems due to the [special logic|https://github.com/jenkinsci/jenkins/blob/a174f985d4574f9056afd497694456ee0988a975/core/src/main/resources/lib/form/select/select.js#L168-L179] included in refillOnChange. Note: Even if it's especially visible when playing with credentials and the {{includeEmptyValue()}} method, the behavior is coming from f:select. |
New:
h3. Reproduction
Code in Jelly {code:java} <f:entry title="${%Test select}" field="testSelect"> <f:select/> </f:entry> {code} Code in Java {code:java} // in Describable private String testSelect; public String getTestSelect() { return testSelect; } @DataBoundSetter public void setTestSelect(String testSelect) { this.testSelect = testSelect; } // [...] // in Descriptor public ListBoxModel doFillTestSelectItems(@QueryParameter String testSelect){ ListBoxModel items = new ListBoxModel(); items.add(new ListBoxModel.Option("- none -", "", testSelect.isBlank())); items.add(new ListBoxModel.Option("Test 1", "test1", testSelect.equals("test1"))); items.add(new ListBoxModel.Option("Test 2", "test2", testSelect.equals("test2"))); items.add(new ListBoxModel.Option("Test 3", "test3", testSelect.equals("test3"))); return items; } {code} h4. Scenario preparation * Open the form * "- none -" is selected * Select test2 * "test2" is now selected * Save and come back OR apply and refresh * "test2" is still selected * Select test3 * "test3" is now selected * Save and come back OR apply and refresh * "test3" is still selected * {color:#FF0000}*[Now the bug, see attached gif]*{color} * Select "- none -" * (2 rounds of doFill) * "test2" is now selected * Re-select "- none -" * (1 round of doFill, as usual) * This time it's working, "- none -" is now selected It seems due to the [special logic|https://github.com/jenkinsci/jenkins/blob/a174f985d4574f9056afd497694456ee0988a975/core/src/main/resources/lib/form/select/select.js#L168-L179] included in refillOnChange. Note: Even if it's especially visible when playing with credentials and the {{includeEmptyValue()}} method, the behavior is coming from f:select. |