addOptions - format the text/value shown in listbox (select)

View: New views
2 Messages — Rating Filter:   Alert me  

addOptions - format the text/value shown in listbox (select)

by andle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a java-method returning a collection with javabeans with countries
which have an id and a name
something like ('SE', 'Sweden), ('DK', 'Denmark')

I use addOptions like this:
dwr.util.addOptions('mylistbox', data, 'id', 'name');

data is the result from dwr with id and name for many countries.

Is there a way to format the text that is shown in the listbox?
Now in the listbox the name of the countries is shown:
like "Sweden, Denmark", etc
The value in the listbox is the "id" of the country: SE, DK, etc

I would like to format the text (shown to the user in the listbox), so
more than the country name is shown.
For example, I would like the result to be
'SE Sweden', 'DK Denmark' in the listbox.
Is there a way with addOptions to do this?
/Andreas

RE: addOptions - format the text/value shown in listbox (select)

by mikewse :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hej Andreas,

> I have a java-method returning a collection with javabeans
> with countries
> which have an id and a name
> something like ('SE', 'Sweden), ('DK', 'Denmark')
>
> <snip>
>
> The value in the listbox is the "id" of the country: SE, DK, etc
>
> I would like to format the text (shown to the user in the
> listbox), so
> more than the country name is shown.
> For example, I would like the result to be
> 'SE Sweden', 'DK Denmark' in the listbox.
> Is there a way with addOptions to do this?

You can supply functions instead of property names, so something
like this should fix your problem:
  dwr.util.addOptions('mylistbox', data, 'id',
    function(x){return x.id+" "+x.name;});

Best regards
Mike (Göteborg ;-)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...