In config.jelly, I have:
<f:entry field="field1">
<f:select/>
</f:entry>
And corresponding java code that fills above components with value:
public ListBoxModel doFillField1Items() {
...
}
When the user enters the config page, field field1
is filled with the first value provided by method doFillField1Items()
.
And my question:
Is it a way to configure(either in jelly or java) this <f:select/>
component to have initially no selection for field field1
.
From HTML point of view there is no such thing as "no selection". <select>
tag if has any <option>
available then will be selected. Only way that "nothing is selected" is to remove all options from it.
I don't know Jelly but you probably want to achieve code like this:
<select required>
<option selected disabled value="">No option selected</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
Code above will tell browser to pre-select option "No option selected", but because it's disabled, then after changing selection user will not be able to choose back "No option selected". Combined required
attribute added to <select>
and <option value="">
will force user to make a selection (in theory) because otherwise <form>
(assuming that you have one) will be ivalid.