Saturday, November 23, 2013

Re: ListBox and default selection

In plain old HTML, I can create a select tag, and specify one option as selected, so that it comes up as the selection by default, or gets selected if the user resets the form.

GWT doesn't appear to offer this capability - I don't see anything like setDefaultSelectedIndex(int index), or addItem(String itemText, boolean defaultSelected).  Is this an oversight, or something that was done deliberately?

Probably an oversight. ListBox also does not support option groups. However you can actually set a default selection when dropping down to the DOM Element layer:

SelectElement select = listBox.getElement().cast();
select.getOptions().getItem(index).setDefaultSelected(true);


Hmm, that being said, it seems like there's no reset capability anyway - a ResetButton apparently belongs only in a FormPanel, and there's no reset method in ListBox.

If you have a FormPanel that contains the ResetButton and your ListBox then the ResetButton should just work. If you don't have a FormPanel then you have to implement the reset logic yourself as the browser won't do it for you automatically.


If you want to see an API for default selection on ListBox then you should file an issue for it (and maybe also provide a patch).

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment