Hello Christian, thanks for giving it a try. Sure your first raised point is a bug and i have just forgotten to include a check. Its fixed already. The point with the wrong preselection is a bit more complicated. With the (formally not working) setModel, you achieve the creation of the binding and with that, the initialization of the form. This initialization searches for "book" as model, which does not exist because you haven't specified the converters yet. And as the select box is in the selection mode "one", it has to select something which is the first element. That set invokes the setting of the data in the form model. Specifying the converters and adding the model in that order does the job. Regards, Martin
panyasan wrote: > > > MartinWittemann wrote: >> >> Hi, >> the model is available via closure in your example. Just paste my code >> unter your code postet some mails ago and its working. >> > > Thanks! Ok, I got it working ... almost ! Here is the (slightly modified) > code for the playground (current trunk, of course): > > > // select box > var data = > [{"value":"article","icon":"icon\/16\/actions\/document-new.png","label":"Article"},{"value":"book","icon":"icon\/16\/actions\/document-new.png","label":"Book > (Monograph)"},{"value":"chapter","icon":"icon\/16\/actions\/document-new.png","label":"Book > Chapter"}]; > var model = qx.data.marshal.Json.createModel(data,true); > var selectBox = new qx.ui.form.SelectBox(); > var controller = new qx.data.controller.List( null, selectBox, "label" ); > controller.setIconPath("icon"); > controller.setModel(model); > > // form > var form = new qx.ui.form.Form(); > form.add(selectBox,"Type",null,"type"); > form.add(new qx.ui.form.TextField(),"Author",null,"author"); > form.add(new qx.ui.form.TextField(),"Title",null,"title"); > > // render form > this.getRoot().add(form.createView()); > > // form controller and model > var formController = new qx.data.controller.Form(null,form); > var formModel = qx.data.marshal.Json.createModel({ > 'type' : "book", > 'author' : "Doe, John", > 'title' : "My first publication", > },true); > > // if this is left out, an error ("this._yC is null") is thrown > formController.setModel(formModel); > > var model2target = {converter: function(data) { > for (var i = 0; i < model.getLength(); i++) { > var item = model.getItem(i); > if (item.getValue() == data) { > return item; > } > } > return model.getItem(0); > }}; > var target2model = {converter: function(data) { > return data.getValue(); > }}; > formController.addBindingOptions("type", model2target, target2model); > > // this should populate the form > formController.setModel(formModel); > > // listen for form changes > formModel.addListener("changeBubble",function(e){ > var data = e.getData(); > this.info(data.name + " changed from " + data.old + " to " + > data.value); > },this); > > Two problems remain: > > 1) if you leave out the first "formController.setModel(formModel);" an > error is thrown. I think you should be able to add binding options before > you set the form data model. > > 2) The select box is not preselected to the value set in the form data > model (in this case "book"). > > Can you look into this? > > Thanks, > > Christian > > -- View this message in context: http://n2.nabble.com/How-to-use-data-binding-for-a-SelectBox-which-is-intended-for-single-selection-tp3656721p3697933.html Sent from the Q&A (solved) 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