Hi Martin,
Thanks for the code.
But I was hoping to have all the bindings created by
qx.data.controller.Object.It's a little bit strange to have just that case
treated different.
Here what I've done:
var fields = this._fields;
controller.addTarget(this._fields["type"], "selection", "type", true,
{
converter : function(data) {
for (var i=0, len=fields["type"].getChildren().length; i < len; i++)
{
if (fields["type"].getChildren()[i].getModel() == data)
return [fields["type"].getChildren()[i]];
}
}
}, {
converter : function(data) {
return data[0].getModel();
}
});
It works but I have one last question: how to change the converter scope?
the default for "this" is the options map. I want to change that scope to be
able to remove the first line: var fields = this._fields;
On Fri, Sep 4, 2009 at 4:44 AM, MartinWittemann
<[email protected]>wrote:
>
> Hello,
>
> there are two reasons why your code can not work. First, there is no event
> for ModelSelection. So you can not bind that like you did. Second,
> ModelSelection always wraps its selections in an array.
> Take a look at the following code to see how you can set up a proper two
> way
> binding for a RadioButtonGroup using the ModelSelection:
>
> qx.Class.define("Model", {
> extend : qx.core.Object,
> properties : {
> name : {
> event : "changeName",
> init : "r0"
> }
> }
> });
>
> var rc = new qx.ui.form.RadioButtonGroup();
> for (var i = 0; i < 10; i++) {
> var rb = new qx.ui.form.RadioButton("r" + i);
> rb.setModel("r" + i);
> rc.add(rb);
> }
> this.getRoot().add(rc);
>
>
> var model = new Model();
>
> model.bind("name", rc, "modelSelection", {
> converter : function(data) {
> return [data];
> }});
>
> rc.bind("selection", model, "name", {
> converter : function(data) {
> return data[0].getModel();
> }});
>
> This code works when the property stored in the model is the same than
> stored in the RadioButtons model. If you have something different, you have
> to change the coverter for this. But take care, this code only works for
> RadioButtonGroups and other single selection widget with the selection mode
> of "one".
>
> To your missing else case... right. :D I must have missed that one
> completely! Just updated the trunk with it. Thanks for the hint!
>
> Regards,
> Martin
>
>
>
> Krycek wrote:
> >
> > Hi,
> > I'm trying to use the new "model" property in RadioButtons, here is what
> I
> > have done so far:
> >
> >
> > --code--
> >
> > var types =
> > {
> > "r" : "Type 1",
> > "c" : "Type 2",
> > "d": "Type 3"
> > };
> >
> > this._fields["type"] = new qx.ui.form.RadioButtonGroup();
> > this._fields["type"].setLayout(new qx.ui.layout.HBox(5));
> >
> > for (var type in types)
> > {
> > var radioButton = new qx.ui.form.RadioButton(types[type]);
> > radioButton.setValue(type == 'r');
> > radioButton.setModel(type);
> > radioButton.setUserData("value", type);
> >
> > this._fields["type"].add(radioButton);
> > }
> >
> > -- code --
> >
> > if I call: this._fields["type"].setModelSelection(['c']), "Type 2" is
> > selected as expected (very good).
> >
> > But later on the code I have some bindings like:
> >
> > controller.addTarget(this._fields["relevance"], "value", "relevance",
> > true);
> >
> > How do I set the binding to auto select the right choice depending on the
> > model.type value?
> >
> > Do I need to use converters? I hope I don't need to use converters every
> > time I'm going to use RadioButtons.
> >
> > By the way, new qx.ui.form.RadioButtonGroup(new qx.ui.layout.HBox(5))
> > doesn't work, is that suppose to be like that? Setting the layout later
> > works ok, though.
> >
> > I guess an "else" is missing here:
> >
> > if (layout == null) {
> > this.setLayout(new qx.ui.layout.VBox(4));
> > }
> >
> >
> ------------------------------------------------------------------------------
> > Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> > 30-Day
> > trial. Simplify your report design, integration and deployment - and
> focus
> > on
> > what you do best, core application coding. Discover what's new with
> > Crystal Reports now. http://p.sf.net/sfu/bobj-july
> > _______________________________________________
> > qooxdoo-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/RadioButtonGroup-and-ModelSelection-tp3573156p3578159.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel