Thanks Derrell & Chris, this seems to work quite well & makes the code
itself look a bit cleaner.
Ken

On Thu, Dec 17, 2009 at 5:01 AM, Christian Schmidt <
[email protected]> wrote:

>  Hi Ken, Hi Derrell,
>
> yes that's correct, change the selection mode to "single" and than back to
> "one". Here a playground example:
> http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22var%2520selectBox%2520%253D%2520new%2520qx.ui.form.SelectBox%28%29%253B%250AselectBox.getChildrenContainer%28%29.setSelectionMode%28%2522single%2522%29%253B%250A%250AselectBox.addListener%28%2522changeSelection%2522%252C%2520function%28e%29%2520%257B%250A%2520%2520alert%28e.getData%28%29%255B0%255D.getLabel%28%29%29%253B%250A%257D%29%253B%250A%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem1%2522%29%29%253B%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem2%2522%29%29%253B%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem3%2522%29%29%253B%250A%250Avar%2520button%2520%253D%2520new%2520qx.ui.form.Button%28%25
> 22Change%2520selection%2520mode%2522%29%253B%250Abutton.addListener%28%2522execute%2522%252C%2520function%28e%29%2520%257B%250A%2520%2520selectBox.getChildrenContainer%28%29.setSelectionMode%28%2522one%2522%29%253B%250A%257D%29%253B%250A%250Avar%2520doc%2520%253D%2520this.getRoot%28%29%253B%250Adoc.add%28selectBox%252C%2520%257Bleft%253A%252020%252C%2520top%253A%252020%257D%29%253B%250Adoc.add%28button%252C%2520%257Bleft%253A%252020%252C%2520top%253A%252050%257D%29%253B%250A%250A%22%7D<http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22var%2520selectBox%2520%253D%2520new%2520qx.ui.form.SelectBox%28%29%253B%250AselectBox.getChildrenContainer%28%29.setSelectionMode%28%2522single%2522%29%253B%250A%250AselectBox.addListener%28%2522changeSelection%2522%252C%2520function%28e%29%2520%257B%250A%2520%2520alert%28e.getData%28%29%255B0%255D.getLabel%28%29%29%253B%250A%257D%29%253B%250A%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem1%2522%29%29%253B%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem2%2522%29%29%253B%250AselectBox.add%28new%2520qx.ui.form.ListItem%28%2522ListItem3%2522%29%29%253B%250A%250Avar%2520button%2520%253D%2520new%2520qx.ui.form.Button%28%2522Change%2520selection%2520mode%2522%29%253B%250Abutton.addListener%28%2522execute%2522%252C%2520function%28e%29%2520%257B%250A%2520%2520selectBox.getChildrenContainer%28%29.setSelectionMode%28%2522one%2522%29%253B%250A%257D%29%253B%250A%250Avar%2520doc%2520%253D%2520this.getRoot%28%29%253B%250Adoc.add%28selectBox%252C%2520%257Bleft%253A%252020%252C%2520top%253A%252020%257D%29%253B%250Adoc.add%28button%252C%2520%257Bleft%253A%252020%252C%2520top%253A%252050%257D%29%253B%250A%250A%22%7D>
>
> Cheers,
> Chris
>
> Am 16.12.2009 23:21, schrieb Derrell Lipman:
>
> On Wed, Dec 16, 2009 at 16:50, Ken MacDonald <[email protected]> wrote:
>
>> Hi,
>> I'm trying to figure out how to trigger a 'changeSelection' event.
>> Situation is that I have a SelectBox(), have added a listener on
>> 'changeSelection'. When I add the first item to the SelectBox, the listener
>> fires. Adding more items after that, the listener does NOT fire. After I'm
>> done adding all of the items in the selectBox, I've saved one of the items
>> to select, depending on the time of day, and then do a
>> box.setSelection([saved_item]).
>>
>> Now, if the saved item is the first item, the selection is NOT changed,
>> the listener does not fire; only fires if the saved item is one of the later
>> items.
>>
>> Since the listener firing causes a bunch of stuff including a DB query,
>> I'd rather only fire the listener once, with the correct item.
>>
>> I would like to populate the entire list, and then
>> setSelection([saved_item]), and have the listener invoked only that one
>> time, with the proper item selected. I tried:
>>
>> (disable listener)
>>
>> add several items, keeping one as the final selection...
>>
>> setSelection([saved_item])
>> (enable the listener again)
>> myselectbox.fireEvent('changeSelection');
>>
>> but my listener did not seem to be called, and the app went off to
>> neverland as well. What is the proper way to fireEvent() on a
>> 'changeSelection' listener, OR what's the correct way to achieve what I'm
>> attempting? Can I pass the saved_item to the fireEvent, or...???
>>
>
> I suspect you've set the selection mode to "one" which requires a
> selection, so the first item gets implicitly selected. Try setting the
> selection mode to "single" with:
>
>   myselectbox.getChildrenContainer().setSelectionMode("single");
>
> before adding any items. You should be able to have your listener active
> the whole time as long as you don't set a selection explicitly. Then, once
> done adding everything, set your selection. You could then change the
> selection mode to "one" if you want to ensure that henceforth there is
> always at least one item selected.
>
> Derrell
>
>
>
>
>
> --
> Christian Schmidt
> Software Entwickler
>
> 1&1 Internet AG - Web Technologies
> Ernst-Frey-Straße 9 · DE-76135 [email protected]
>
> Amtsgericht Montabaur / HRB 6484
> Vorstände: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas 
> Gottschlich, Robert Hoffmann, Markus Huhn, Hans-Henning Kettler, Dr. Oliver 
> Mauss, Jan Oetjen
> Aufsichtsratsvorsitzender: Michael Scheeren
>
>
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and
> easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to