loading data into a form via ajax

6 views
Skip to first unread message

Александр Зайцев

unread,
Sep 24, 2009, 6:18:25 AM9/24/09
to inputex
Is there a ready mechanism for loading data into a form via ajax?
How to send data from a form via ajax clear to me.
Something like:

new YAHOO.inputEx.Form( {
...

ajax: {
method: 'POST',
uri: 'submit.php',
callback: {
success: function(o) { alert("ok", o); },
failure: function(o) { alert("Error", o); }
},
...
});

And how to implement load data into a form?
Is there a built-in mechanism?
Something like the method load (url)?

neyric

unread,
Oct 25, 2009, 11:28:14 AM10/25/09
to inputex
There is no loading method via Ajax yet.
You can do the Ajax request and call the setValue method in the
callback:

YAHOO.util.Connect.asyncRequest('GET','myUrl.php', {
success: function(o) {
var obj = YAHOO.lang.JSON.parse(o.responseText);
form.setValue(obj);
}
});

Cheers

robinne

unread,
Nov 11, 2009, 12:12:51 AM11/11/09
to inputex
What is "form" here? (form.setValue(obj)) I have created a Inputexform
using your example code..

YAHOO.util.Event.addListener(window, "load", function(){
new inputEx.Form({
parentEl: 'inputExForm',
fields: [ .....(etc)

So, how do I access the form that gets created. Do I need to set var
myform=new inputEx.Form({ ... ?

Do you know how I would return the correct json from django? I am
returning json, but it is not binding to the inputEx fields. This is
what my json looks like, where "Username" and "City" should match the
name of my inputEx fields.

[{"pk": 1, "model": "ManageProducts.member", "fields": {"Username":
"robinne2", "City": "New York", ...(etc)}]

Thanks.

Eric Abouaf

unread,
Nov 22, 2009, 10:36:19 AM11/22/09
to inp...@googlegroups.com

2009/11/11 robinne <deve...@computer-shoppe.net>

What is "form" here? (form.setValue(obj)) I have created a Inputexform
using your example code..

YAHOO.util.Event.addListener(window, "load", function(){
           new inputEx.Form({
           parentEl: 'inputExForm',
           fields:  [ .....(etc)

So, how do I access the form that gets created. Do I need to set var
myform=new inputEx.Form({ ... ?


"form" is indeed the instance of the inputEx.Form you created before.

 
Do you know how I would return the correct json from django? I am
returning json, but it is not binding to the inputEx fields. This is
what my json looks like, where "Username" and "City" should match the
name of my inputEx fields.

[{"pk": 1, "model": "ManageProducts.member", "fields": {"Username":
"robinne2", "City": "New York", ...(etc)}]


You should store the generated json into a var.

var myJson = <% my json from django %>;

form.setValue() requires a hash which seems to correspond to "myJson.fields" :

form.setValue(myJson.fields);
 
Cheers
Reply all
Reply to author
Forward
0 new messages