[ 3 posts ]

Kai Aeberli

  • Username: kai_aeberli
  • Joined: Wed Apr 20, 2011 10:52 am
  • Posts: 4
  • Offline
  • Profile

Reloading datasource after submitting form

Post Posted: Wed Apr 20, 2011 11:01 am
+0-
Hi,

i have the following code:

Code:

var dataSource = new Y.DataSource.IO({
   source: "http://localhost"
});

Y.on('click', login, '#btn1', this, true);

var cfg = {
    method: 'GET',
    form: {
        id: 'myform',
        useDisabled: false
    }
};
function login() {
    Y.io('insertreq.php', cfg);
    Y.on('io:success', onSuccess, this);
    Y.on('io:failure', onFailure, this);
   
};
function onSuccess(id,response,args) {
    
    document.getElementById('myformmsg').innerHTML = response.responseText;
    document.forms['myform'].reset();

    dataTable.datasource.load({
       request: "/getdata.php"
       });
   
};
function onFailure(id,response,args) {
    document.getElementById('myformmsg').innerHTML = "Error, retry...";
    document.forms['myform'].reset();
};


I am sending a form to "insertreq.php", updating a table. The answer is displaid in a html field "myformmsg".

After the form is sent, i am updating the datasource for a YUI3 datatable.

My problem: after clicking on the submit button, it seems that the "io:success" event keeps firing, every time i reload the datasource
because both use the IO functionality.

Could someone help me?

Thanks a lot for your time!

Regards,

Kai

Alberto Santini

YUI Contributor

  • Offline
  • Profile
Tags:

Re: Reloading datasource after submitting form

Post Posted: Thu Apr 21, 2011 1:24 am
+0-
Hello Kai.

You are using global events.

http://developer.yahoo.com/yui/3/io/#configuration

You should use transaction events, adding the handlers to your configuration object.

For instance,

Code:
var cfg = {
   method: 'GET',
        form: {
            id: 'myform',
            useDisabled: false
        },
   on: {
       success: onSuccess,
       failure: onFailure
   }
};


Don't forget to comment out Y.on lines.

Hope that helps,
Alberto

Kai Aeberli

  • Username: kai_aeberli
  • Joined: Wed Apr 20, 2011 10:52 am
  • Posts: 4
  • Offline
  • Profile

Re: Reloading datasource after submitting form

Post Posted: Wed Apr 27, 2011 6:58 am
+0-
Thanks a lot! It works perfectly.
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum