I tried your suggestion of Option.EMPTY_OPTION and it works.
One might think the other way around: if the Select is required, then my
option-list only contains possible values, and not an empty one. It's a
long search if you don't know this specific behaviour. :)
Thanks.
On 10/27/2009 11:11 AM, Bob Schellink wrote:
Just to be clear, Click will assume that the first Option is the
"nonselected" option. If the first Option is selected (doesn't matter
what that Option's value is), then Click will raise the validation
error. So by adding an initial empty option, all other options are
treated as valid.
Bob Schellink wrote:
Hi WarnerJan,
It seems a bit odd at first but it makes sense. If the only values
one can select are 0,1,2,3 then there is no need to set the Select as
required since the Select will always have a value.
If however the Select is set to required, then there should be an
"nonselected" value for the user to choose from. For the Select that
value is an empty string. So normally one would use the
Option.EMPTY_OPTION:
Select select = new Select();
select.setRequired(true);
select.add(Option.EMPTY_OPTION);
select.add(...);
Or if you want to display a value for the "nonselected" value, do this:
Select select = new Select();
select.setRequired(true);
select.add(new Option("", "Please select a value..."));
select.add(new Option("M", "Male");
select.add(new Option("F", "Female");
See the Select Javadoc for more examples of the required property.
kind regards
bob
WarnerJan Veldhuis wrote:
Hi,
I have a set of values, 0 to 3 which I put in a Select, which is set
to be required. But the validate fails for the value zero. It says I
must select a value. Is that how it's supposed to work?
Cheers,
WarnerJan