Another dumb SelectBox question

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Another dumb SelectBox question

JB-5
How the heck to the get the value of the selected item?  That seems a
little more complicated than it probably should be.  I'm scouring the
documentation and not coming up with anything.  Where the heck is the
selected value actually stored?

Here is what I know already:
SelectBox is derived from List and provides getSelection() which returns
an array of type Widget.

Here is what I do not quite understand:
In the case of a SelectBox that would be what, an array with 1 element?  
Not sure why you would do that in the case of a derived SelectBox which
can only ever have a single selection anyway but OK, so now you have a
one element array containing a Widget object which again as far as I can
tell from the documentation has no property or function with which to
retrieve the actual value??

Jared


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

Krycek
In each ListItem set the value using .setModel(Value): http://demo.qooxdoo.org/devel/apiviewer/#qx.ui.form.ListItem~setModel
And use selectbox.getModelSelection() to get the array of selected values: http://demo.qooxdoo.org/devel/apiviewer/#qx.ui.form.MModelSelection~getModelSelection

It returns an array of values just to be coherent with the selection API used everywhere else in the framework.

On Wed, Oct 21, 2009 at 6:10 PM, JB <[hidden email]> wrote:
How the heck to the get the value of the selected item?  That seems a
little more complicated than it probably should be.  I'm scouring the
documentation and not coming up with anything.  Where the heck is the
selected value actually stored?

Here is what I know already:
SelectBox is derived from List and provides getSelection() which returns
an array of type Widget.

Here is what I do not quite understand:
In the case of a SelectBox that would be what, an array with 1 element?
Not sure why you would do that in the case of a derived SelectBox which
can only ever have a single selection anyway but OK, so now you have a
one element array containing a Widget object which again as far as I can
tell from the documentation has no property or function with which to
retrieve the actual value??

Jared


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

Petr Kobalíček
In reply to this post by JB-5
Hi,

I will probably not help you, but I can try to explain some things.
ListItem is also widget so you are interesting in it. There is no
value property in ListItem, but there is model property that has
exactly same function, so if you want to get database id or something
you can do it this way:

var item = new qx.ui.form.ListItem();
item.setModel("MyId");

...

var list = ... // your list
var sel = list.getSelection(); // selection

// detect if selection contains something
if (sel.length)
{
  var item = sel[0];
  alert(item.getModel()); // should alert MyId if it's our item
}

I think that most important for you is model property and it's what you need:)

--
Best regards
- Petr Kobalicek <http://kobalicek.com>

2009/10/21 JB <[hidden email]>:

> How the heck to the get the value of the selected item?  That seems a
> little more complicated than it probably should be.  I'm scouring the
> documentation and not coming up with anything.  Where the heck is the
> selected value actually stored?
>
> Here is what I know already:
> SelectBox is derived from List and provides getSelection() which returns
> an array of type Widget.
>
> Here is what I do not quite understand:
> In the case of a SelectBox that would be what, an array with 1 element?
> Not sure why you would do that in the case of a derived SelectBox which
> can only ever have a single selection anyway but OK, so now you have a
> one element array containing a Widget object which again as far as I can
> tell from the documentation has no property or function with which to
> retrieve the actual value??
>
> Jared
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

JB-5
That was helpful! However when I look at the documentation and your
code, the following seems to be the case:
So help me understand the difference between the label and the model.
Moreover, the model can be managed but the label can only be set when
the constructor is called?

Following one of the examples, I was doing this:

selbx.add(new qx.ui.form.ListItem("Foo"));
selbx.add(new qx.ui.form.ListItem("Bar"));
selbx.add(new qx.ui.form.ListItem("For Good"));

This essentially becomes useless without seeing the model property.
Also, if the label is specified like this where is it stored? there is
no label property, yet it does show up in the select box drop down.

Do you understand the source of my confusion? If my interpretation of
the docs and your example is correct then it does not really make sense
that the value can be manipulated but the label cannot, does it?

Jared



Petr Kobalíček wrote:

> Hi,
>
> I will probably not help you, but I can try to explain some things.
> ListItem is also widget so you are interesting in it. There is no
> value property in ListItem, but there is model property that has
> exactly same function, so if you want to get database id or something
> you can do it this way:
>
> var item = new qx.ui.form.ListItem();
> item.setModel("MyId");
>
> ...
>
> var list = ... // your list
> var sel = list.getSelection(); // selection
>
> // detect if selection contains something
> if (sel.length)
> {
>   var item = sel[0];
>   alert(item.getModel()); // should alert MyId if it's our item
> }
>
> I think that most important for you is model property and it's what you need:)
>
>  

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

JB-5
In reply to this post by Petr Kobalíček
Again, thanks for you reply, that was extremely helpful!!

OK, I did empirically determine how this works. OK, I get what qooxdoo
is trying to do here and I am all for consistency but come on...there
has got to be a point at which common sense takes over?

Since the SelectBox widget can only ever have a single value selected,
shouldn't the SelectBox object override getSelection() such that it
returns a single value only and not always a one element array?

Also, what is with calling a data value "Model" that isn't making much
sense to me either.

Additionally, making clear in the documentation the distinction between
a 'label' and the model property would be helpful. I suitable default
behavior like initializing the model to the label value upon creation
would also make an immense amount of sense, no?!

Jared


Petr Kobalíček wrote:

> Hi,
>
> I will probably not help you, but I can try to explain some things.
> ListItem is also widget so you are interesting in it. There is no
> value property in ListItem, but there is model property that has
> exactly same function, so if you want to get database id or something
> you can do it this way:
>
> var item = new qx.ui.form.ListItem();
> item.setModel("MyId");
>
> ...
>
> var list = ... // your list
> var sel = list.getSelection(); // selection
>
> // detect if selection contains something
> if (sel.length)
> {
>   var item = sel[0];
>   alert(item.getModel()); // should alert MyId if it's our item
> }
>
> I think that most important for you is model property and it's what you need:)
>
>  

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

Loïc Bresson -- Novlog
Hi Jared.

> Since the SelectBox widget can only ever have a single value selected,
> shouldn't the SelectBox object override getSelection() such that it
> returns a single value only and not always a one element array?
The current getSelection() is coherent with the rest of the selection API, and
IMHO it is fine. This way when you want the selection of a widget, you don't
have to ask yourself "Do I get an array or do I get one widget ? Let's go check
the doc". Furthermore, you can implement generic algorithms which retrieve the
selected elements of several different widgets. Having a different return type
would make it necessary to check the classname of the widget.

> I suitable default
> behavior like initializing the model to the label value upon creation
> would also make an immense amount of sense, no?!
I agree with that. That would just be a "shorcut" for people have the same
label and model properties values. But maybe some people want their model
property set to "null" ?
That would also be great to be able to initialize the model property in the
constructor, instead of the deprecated value property.


--
Loïc Bresson


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

Fabian Jakobs
Administrator
In reply to this post by JB-5
Hi Jared,

> That was helpful! However when I look at the documentation and your
> code, the following seems to be the case:
> So help me understand the difference between the label and the model.
> Moreover, the model can be managed but the label can only be set when
> the constructor is called?
>
> Following one of the examples, I was doing this:
>
> selbx.add(new qx.ui.form.ListItem("Foo"));
> selbx.add(new qx.ui.form.ListItem("Bar"));
> selbx.add(new qx.ui.form.ListItem("For Good"));
>
>  

In this case you can simply use:

selbx.getSelection()[0].getLabel();

http://demo.qooxdoo.org/devel/playground/#%7B%22code%22%3A%20%22%250Avar%2520selbx%2520%253D%2520new%2520qx.ui.form.SelectBox%28%29%253B%250A%250A%2520selbx.add%28new%2520qx.ui.form.ListItem%28%2522Foo%2522%29%29%253B%250A%2520selbx.add%28new%2520qx.ui.form.ListItem%28%2522Bar%2522%29%29%253B%250A%2520selbx.add%28new%2520qx.ui.form.ListItem%28%2522For%2520Good%2522%29%29%253B%250A%250Athis.getRoot%28%29.add%28selbx%29%250A%250Aalert%28selbx.getSelection%28%29%255B0%255D.getLabel%28%29%29%253B%250A%22%7D

Best Fabian

--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG - Web Technologies
Ernst-Frey-Straße 9 · DE-76135 Karlsruhe
Telefon: +49 721 91374-6784
[hidden email]

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


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Another dumb SelectBox question

JB-5
In reply to this post by Loïc Bresson -- Novlog


Loïc Bresson -- Novlog wrote:

> Hi Jared.
>
>  
>> Since the SelectBox widget can only ever have a single value selected,
>> shouldn't the SelectBox object override getSelection() such that it
>> returns a single value only and not always a one element array?
>>    
> The current getSelection() is coherent with the rest of the selection API, and
> IMHO it is fine. This way when you want the selection of a widget, you don't
> have to ask yourself "Do I get an array or do I get one widget ? Let's go check
> the doc". Furthermore, you can implement generic algorithms which retrieve the
> selected elements of several different widgets. Having a different return type
> would make it necessary to check the classname of the widget.
>
>  
I see your point.  That makes sense.



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel