Hello Daniel,
I think i did get what you try to achieve. But a much better solution to
this is not really possible. You have two different kind of data in your
model. One is the id, which is the model (representative of the item) and
the other is the name, which contains UI relevant information. So you have
to convert in some place to get those two models apart.
I do have one minor improvement for your code.

var certtypeModel = new qx.data.Array(); 
var isotypes = this.data.isotypes; 
for (var m in isotypes) { 
  certtypeModel.push(m); 
}

You can create an data array right away and use that as model.

What i have seen additionally in your code is, that you are using the
resetter explicitly. Do you know that the form hast the same functionality
than the resetter? It uses the resetter to enable that feature for all users
of the form object, too.

Regards,
Martin


Daniel Hirtzbruch-2 wrote:
> 
> 
> Hello Martin,
> 
> that's what I need:
> I've got an Array of Datasets (containing a dataset ID and a name),
> retrieved from a MySQL Database. I need a SelectBox within my form which
> has
> to display the name as label and the ID as value on send of the form. What
> I
> want to do is bind the chosen data to a model to serialize it and post it
> to
> my backend script.
> 
> That's my current source:
> 
>         var form = new qx.ui.form.Form();
>         var certtype = new
> qx.ui.form.SelectBox().set({required:true,width:200});
>         var recipient_company = new
> qx.ui.form.TextField().set({required:true});
>         var recipient_address = new
> qx.ui.form.TextField().set({required:true});
>         var recipient_zipcode = new
> qx.ui.form.TextField().set({required:true});
>         var recipient_city = new
> qx.ui.form.TextField().set({required:true});
>         
>         //////////////////////////////////////////////////////////////
>         // extract the models to an separate array
>         var certtypeModelData = [];
>         var isotypes = this.data.isotypes;
>         for (var m in isotypes) {
>               certtypeModelData.push(m);
>         }
>         var certtypeModel =
> qx.data.marshal.Json.createModel(certtypeModelData,true);
> 
>         var certtypeController = new qx.data.controller.List(null,
> certtype);
>         certtypeController.setLabelOptions({converter: function(value) {
>           return isotypes[value].types_name;
>         }});
>         certtypeController.setModel(certtypeModel);
>         this.debug("Selected Model: " +
> certtype.getModelSelection().getItem(0));
>         //////////////////////////////////////////////////////////////
>         
>         form.add(certtype, "Zertifizierung", null, "certtype");
>         form.add(recipient_company, "Firma", null, "recipient_company");
>         form.add(recipient_address, "Adresse", null, "recipient_address");
>         form.add(recipient_zipcode, "PLZ", null, "recipient_zipcode");
>         form.add(recipient_city, "Ort", null, "recipient_city");
> 
>         var resetter = new qx.ui.form.Resetter();
>         resetter.add(certtype);
>         resetter.add(recipient_company);
>         resetter.add(recipient_address);
>         resetter.add(recipient_zipcode);
>         resetter.add(recipient_city);
>         
>         var controller = new qx.data.controller.Form(null, form);
>         var model = controller.createModel();
> 
>         var startButton = new qx.ui.form.Button("Generierung starten");
>         form.addButton(startButton);
> 
>         // add form view to page / tab
>         tab.add(form.createView(qx.ui.form.renderer.Single));
>         
>         // binding
>         var controller = new qx.data.controller.Form(null, form);
>         var model = controller.createModel();
> 
>         startButton.addListener("execute",function() {
>               manager.validate();
>         },this);
>         
>         manager.addListener("complete", function() {
>           if (manager.getValid()) {
>               var p_string = qx.util.Serializer.toJson(model);
>               var request = new
> qx.io.remote.Request("backend/data/addCertificate.php", "POST",
> "text/plain");
>               request.setFormField("cert",p_string);
>                       
> request.addListener("completed",this.__generateCertificate,this);       
>                       request.send();
>                       resetter.reset();
>           }
>         },this);
> 
> 
> 
> The array looks like this in FireBug:
> isotypes: Object 
>   1: Object 
>     types_name: Zert A1
>   2: Object 
>     types_name: Zert B5 
>   4: Object 
>     types_name: Zert C1
> 
> The index of the isotypes is the dataset ID.
> 
> Hope you understand what I mean?
> Thanks & Regards,
> Daniel
> 
> 
> Martin Wittemann wrote:
>> 
>> this code really looks like there should be an easier solution to this. I
>> tried to get your code working in the playground but failed. Could you
>> perhaps explain what you want to achieve? Especially what data you want
>> to
>> have in what property (label, model). If i have that, I think I could get
>> a
>> compacter solution.
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/SelectBox---Databinding-tp25672831p25676685.html
> Sent from the qooxdoo-devel mailing list archive at Nabble.com.
> 
> 
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® 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/devconf
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/SelectBox-Databinding-tp3739687p3741585.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to