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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

squeakman
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

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

Bob Arning
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

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

John McKeon
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 <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

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

squeakman
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,
Frank





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 <[hidden email]
> <mailto:[hidden email]>> 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
>
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

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

John McKeon
Well, if you want to re-render the page, you can just send beSubmitOnChange to the select tag.
 
 
On Thu, Oct 13, 2011 at 11:44 AM, squeakman <[hidden email]> wrote:
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,
Frank





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 <[hidden email]
<mailto:[hidden email]>> 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



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

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

squeakman
On 13/10/2011 11:55 AM, John McKeon wrote:
> Well, if you want to re-render the page, you can just send
> beSubmitOnChange to the select tag.

Wow, that is a thing of beauty. Many thanks

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside