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

squeakman squeakman at gmail.com
Thu Oct 13 15:44:39 UTC 2011

Thanks Bob and John,

I have done as you suggested and it does work.

Here is what the my code now looks like:

(html select)
   id: 'stocksList';
   list: self listOfStocks;

   " Ajax Callback 1 "
   onChange: (html scriptaculous request
      triggerForm: (html scriptaculous element up: 'form'));

   "Ajax Callback 2"
   onChange: (html scriptaculous evaluator callback: [:s | s refresh]);

   "non Ajax Callback "
   callback: [:selStock | self selectedStock: selStock]

If I understand things correctly, on change causes "Ajax Callback 1" to 
be called which causes "non Ajax Callback" to be called where the 
selected stock is updated.

This works but I also want to re-render the page without having to use a 
Submit button. I thought that the "non Ajax Callback" would have caused 
the entire page to be re-rendered but that does not happen.

The "Ajax Callback 2" forces the re-rendering of the page.

One last question to wrap this up: "Is this the prescribed way to do 
this task?".

Thank you very much,

On 13/10/2011 10:40 AM, John McKeon wrote:
> 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
> <mailto: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

More information about the seaside mailing list