Skip to content

Commit

Permalink
Fixed SelectBox bugs
Browse files Browse the repository at this point in the history
git-svn-id: https://qooxdoo-contrib.svn.sourceforge.net/svnroot/qooxdoo-contrib@20024 09f7d036-9b2a-0410-8fbe-9cff4eb17569
  • Loading branch information
cboulanger committed Apr 26, 2010
1 parent fe14269 commit 26ddb4d
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions source/class/dialog/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ qx.Class.define("dialog.Form",
var modelData = {};
for ( var key in formData )
{
modelData[key] = formData[key].value || null;
modelData[key] = formData[key].value !== undefined
? formData[key].value
: null;
}
var model = qx.data.marshal.Json.createModel( modelData );
this.setModel( model );
Expand Down Expand Up @@ -300,15 +302,8 @@ qx.Class.define("dialog.Form",

case "selectbox":
formElement = new qx.ui.form.SelectBox();
var selected = null;
//@todo use data model for list
fieldData.options.forEach( function( item ){
var listItem = new qx.ui.form.ListItem( item.label, item.icon );
listItem.setUserData( "value",
item.value !== undefined ? item.value : item.label
);
formElement.add( listItem );
},this);
var model = qx.data.marshal.Json.createModel( fieldData.options );
new qx.data.controller.List( model, formElement, "label");
break;

case "radiogroup":
Expand Down Expand Up @@ -371,6 +366,38 @@ qx.Class.define("dialog.Form",
* single selection form elements
*/
case "selectbox":
var selectables = formElement.getSelectables();
this._formController.addTarget(
formElement, "selection", key, true, {
"converter" : function( value )
{
var selection=[];
selectables.forEach( function( selectable )
{
//console.warn( key +": " + value + " looking at '" + selectable.getLabel() + "' => " + selectable.getModel().getValue() );
if ( selectable.getModel().getValue() === value )
{
//console.warn("Getting value for " + key +": " + value + " -> Setting selection to '" + selectable.getLabel() + "'..");
selection=[selectable];
}
}, this );

//if(selection.length==0)console.warn("Getting value for " + key +": " + value + " -> No selection found" );
return selection;
}
},
{
"converter" : function( selection )
{
var value = selection[0].getModel().getValue();
//console.warn("Selection is " + ( selection.length ? selection[0].getLabel() : "none" ) + " -> Setting value for " + key +": " + value );
return value;
}
}
);

break;

case "radiogroup":
var selectables = formElement.getSelectables();
this._formController.addTarget(
Expand All @@ -389,15 +416,15 @@ qx.Class.define("dialog.Form",
}
}, this );
}
//console.warn("Value is " + value + " > selection is " + selection);
//console.warn("Getting value for " + key +": " + value + " -> Setting selection to " + ( selection.length ? selection[0].getLabel() : "none" ) );
return selection;
}
},
{
"converter" : function( selection )
{
var value = selection[0].getUserData("value");
//console.warn("Selection is " + selection + " > Value is " + value);
//console.warn("Selection is " + ( selection.length ? selection[0].getLabel() : "none" ) + " -> Setting value for " + key +": " + value );
return value;
}
}
Expand Down

0 comments on commit 26ddb4d

Please sign in to comment.