views:

152

answers:

2

I could not stop the "onClick" event ? If i just use the dom node with the "onclick" event then dojo.stopEvent() works but not with the widget's "onClick". I am getting the error "Unable to load page ......status 0". I found out that this happens when the page refreshes while the Ajax call is being executed. I am posting my code. Any help is appreciated

    // create a button which will be replaced by the Button widget
    var submitButton = dojo.create('button', {type:"submit", id:"submitButton"}, popupFormControlDiv);

    var popupFormSubmitButton = new dijit.form.Button({label: "Create", type:"submit"}, "submitButton");

    dojo.connect(popupFormSubmitButton, "onClick", function(event) {
        //Stop the submit event since we want to control form submission.
        event.preventDefault();
        event.stopPropagation();
        dojo.stopEvent(event);

        // construct the arguments for the post request
        var xhrArgs = {
            form: popupForm,
            url: "/admin/sys-config/registration-form/add",
            handleAs: "text",
            load: function(data) {
                console.log("success");
            },
            error: function(error) {
                console.log("error");
            }
        }
        var deferred = dojo.xhrPost(xhrArgs);
    }); 
A: 

You can return false in the onClick handler function to cancel the form submission.

Alex Cheng
thanks.....i even tried it without any success....the page immediately starts to refresh once the Ajax post is done
rahul
+1  A: 

I just tried with both widgets and regular buttons and both ways I can get the button's click handler to stop the event from ever submitting the form.

DOM only: http://jsbin.com/inoyo4/edit

Widgets: http://jsbin.com/ayomu4/edit

Note that with DOM I connect to onclick while with widgets I connect to onClick. The camel-case notation is used regularly by dijit, and dijit widgets include many event hooks which map to standard DOM events (lowercase) on nodes within the widgets. Unfortunately this can cause confusion.

You may find this worth a read: http://docs.dojocampus.org/quickstart/events

Ken