Re: [qooxdoo-devel] Selectbox form model binding and set selected value to form model
Brought to you by:
ecker,
martinwittemann
From: Martin W. <mar...@1u...> - 2013-07-29 07:38:11
|
Hey, Am 27.07.2013 um 07:24 schrieb dan <dan...@ho...>: > I have searched through the posts and docs but still not sure how to do this. > > Basically can you automatically set the selected value of the selectbox > based on id of the selectbox and the corresponding value in model of the > form when you bind the form. Textboxes get values automatically set by > matching id to form model property, do I have to do this manually with > selectboxes? > > Scenario > > Form with two text fields firtsName,lastName and a select box ContactType > > remote json data via rest bound to the form > json {firstName: "dan", lastName: "green", > ContactType:{__KEY:3} > } > > Then I use a store to bind formController model > var formController = new qx.data.controller.Form(null,form); > store.bind("model", formController , "model"); > > The selectbox has hardcoded data for testing but would in reality be pulled > from remote json > > var rawData = [ > {name: "Home", __KEY: 1}, > {name: "Work", __KEY: 2}, > {name: "Household", __KEY: 3}, > > ] > > //create selectbox model > var model = qx.data.marshal.Json.createModel(rawData); > //create selectbox controller > var gender = new qx.ui.form.SelectBox(); > var genderController = new qx.data.controller.List(null, gender); > genderController.setDelegate({bindItem: function(controller, item, > index) { > controller.bindProperty("name", "label", null, item, index); > controller.bindProperty("__KEY", "model", null, item, index); > }}); > genderController.setModel(model); > > form.add(gender, "ContactType") > > The problem is when I load the from data via the formController > firstName,lastName is filled in correctly but the SelectBox selected value > is not automatically set to the value of ContactType for the forms model. > > Do I have to manually set the value of all my selectboxes or is there > automatic binding like in the form that uses the id of a textbox to find the > corresponding record in the form model. > > Also will the selectbox be two way so if I change the value it changes the > value in the form model. The binding should work the same as the textfield binding. Check out the sample here: http://tinyurl.com/okuqopj Most likely the problem's root is the data in your initial model. you set the contact type to {__KEY: 3} which is itself a model. But you tell the list controller that the model object of the list items is the value of your __KEY property which would be only the 3. So change the initial data from {__KEY: 3} to only 3 and it should work as expected. Regards, Martin |