Form values can be updated using the form views val method or by calling the parent form's populate or val methods.
Example:
var view = new ludo.View({
form:{
submit: {
url : 'save.html',
data:{ save: 1 },
method:'post',
listeners:{
init: function(form){},
success: function(json, form){},
fail: function(text, error, form) {}
}
}
},
children:[
{ type:"form.Text", id:'firstname', name:"firstname", value:"Jane" },
{ type:"form.Text", id:'lastname', name:"lastname", value: "Peterson" }
]
})
To update the firstname here, you can update it directly using
ludo.$('firstname').val('John');
or via the form using
view.getForm().val('firstname', 'John');
or
view.getForm().populate({"firstname" : "John" });
Using Plain jQuery Ajax, you can create a query and thereafter call the populate method with the data you receive from the server.
You can do the same with the form by defining a form.read object.
var view = new ludo.View({
form:{
hiddenFields: ['id'],
read: {
url: 'get-user-data.html', // read url
autoload: true, // autoload data on create
populate: true,
keys: ['id'], // array of form values to add to the view request
data: { 'loadUser' : 1 },
method:'get',
listeners: {
'init' : function(form) {
},
'success': function (json, form) {
},
'fail': function (text, error, form) {
// do something on failure
}
}
},
submit: {
url : 'save.html',
data:{ save: 1 },
method:'post',
listeners:{
init: function(form){},
success: function(json, form){},
fail: function(text, error, form) {}
}
}
},
children:[
{ type:"form.Text", id:'firstname', name:"firstname", value:"Jane" },
{ type:"form.Text", id:'lastname', name:"lastname", value: "Peterson" }
]
})
These are the available properties for the 'read' object above.