izdi
March 23, 2012, 2:24pm
#1
Dear experts,
Is it really possible to create form on-the-fly?? My objective is to set elements programatically by getting values from server. Eg.
dhx.ajax(baseUrl + "/mobile/config/" + id, function(text){
var data = dhx.DataDriver.json.toObject(text);
console.log (data.elements);
$$('channelConfig').config.elements = data.elements ;
$$('channelConfig').render();
});
$$(‘channelConfig’) is a form which I set with default elements initially. After running above code, the form IS NOT rendered with new elements.
Thanks for your help!
Direct assignment will not work, but you can use
//dhx.ui (array of elements, parent collection ui);
dhx.ui(data.elements,$$(‘channelConfig’));
this is the same ui creating method, but if you will provide a collection ui as second parameter, it will replace its elements with new ones ( same will work for toolbars and layouts )
izdi
April 5, 2012, 12:09am
#3
Thanks! Rendering works now… but when submitting the form, it gives error at:
var formData = $$(‘channelConfig’).getValues();
–> Cannot read property ‘childNodes’ of null
Below is the elements I retrieved from server before displaying the form:
{
id:“channelConfig”,
view:“form”,
style:“width:100%;height:100%;”,
scroll:“y”,
css:“basicBG account”,
elements:[{view:“toggle”, label:“Subscription”, id:“subscription” ,click:“submitConfig()”,labelPosition:“left”, labelWidth:100, options:[{value:“1”, label:“On”},
{value:“0”, label:“Off”}]},
],
rules:{}
}