[Seaside] Q on "html select" and how to get selected item in an Ajax callback

John McKeon p3anoman at gmail.com
Thu Oct 13 14:40:20 UTC 2011


I would add that to get the callback to occur via AJAX add:
onChange: (html jQuery ajax serializeThisWithHidden)

And in an attempt to make it clearer:
The parameter in the list: message is a collection of *objects* and the
callback :value will be the selected object. If you give it a collection of
string representations of your Stock objects, you will get back the selected
string representation. But if you give it a collection of Stocks in this
case, you will get back the selected Stock object. Seaside handles the
bookwork for you in determining which object in the collection was selected.
You don't need to deal with the selected index if you don't want to.

On Thu, Oct 13, 2011 at 10:16 AM, Bob Arning <arning at charm.net> wrote:

> We had a very similar question on 28-29 Sept (see "Using the select tag").
> The end result was something like:
>
> (html select)
>     list: self genders;
>     selected: self contact gender;
>     enabled: [:ea | ea notNil];
>     labels: [:ea | ea ifNil: ['---'] ifNotNil: [ea printableVersion]];
>     callback: [:value | self contact gender: value].
>
> Cheers,
> Bob
>
>
> On 10/13/11 10:03 AM, squeakman wrote:
>
> Hello All,
>
> Is there a way to get the selectedItem when the Ajax callback is triggered
> in an html select?
>
> The following code snippet works for me but I think there must be a better
> way.
>
> (html select)
>   id: 'stocksList';
>   list: self listOfStocks;
>   onClick: (html scriptaculous request
>               callback: [:i |self selectedStockIndex: i asNumber + 1.]
>               value: self jsForGetSelectedIndex).
>
>
> Note that I am using the call:value: method.
>
> The "self jsForGetSelectedIndex" returns the javascript code that gets the
> selected index.
>
> In the callback: I use this returned value to figure out which item was
> selected.
>
> Is there a better way to do this?
>
> Thanks,
> Frank
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20111013/0aab6c93/attachment.htm


More information about the seaside mailing list