[Dojo-interest] Question about submit form

zhang uzhang at 263.net
Sat Aug 20 06:26:24 EDT 2011


snippet as below:

in Question.js:    //create a form programmatically
var t = dojo.create("div", { id: "questionContainer" },
dojo.byId("divCenter"));
    dojo.create("div", { id: "tDiv" }, t);
    var n = new dijit.form.Form({
        id: "questionForm",
        enctype: "multipart/form-data",
        action: "",
        method: "get"
    }, "tDiv");
    dojo.create("label", { htmlFor: "tbQueHeader", innerHTML: "标题:" },
n.domNode);
    t = dojo.create("div", { id: "tDiv" }, n.domNode);
    new dijit.form.ValidationTextBox({
        name: "tbQueHeader",
        id: "tbQueHeader",
        maxLength: 40,        
        trim: true,
        required: true,
        selectOnClick: true
    }, t);
    t = dojo.create("div", { id: "tDiv" }, n.domNode);
    new dijit.form.Button({
        type: "submit",
        id: "btnQuestion",
        innerHTML: "提交"
    }, t);

in handler.js:   //create a submit event handler
    var questionSubmitClicked = function (e) {
    e.preventDefault();
    var h = dijit.byId("questionForm");
    if (h.validate()) {
     ...
    }
    else {
     ...
    }
}

in dojoready.js:    //connect submit to event handler
var btnQuestion = dijit.byId("btnQuestion");
dojo.connect(btnQuestion, "onSubmit", questionSubmitClicked);

Q1: When clicked the submit button, the event handler couldn't be fired. I
added a breakpoint on the line e.preventDefault(), but couldn't be hit. If
changed the line
    dojo.connect(btnQuestion, "onSubmit", questionSubmitClicked);
to
    dojo.connect(btnQuestion, "onclick", questionSubmitClicked);
the breakpoint could be hit. Why?

Q2: form.validate() seems not work. If I change "onSubmit" to "onclick",
keep the validateTextBox empty and click the submit button, the page still
redirect to another page. Why?

Anybody can give me a clue? Thanks.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Question-about-submit-form-tp3270320p3270320.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.


More information about the Dojo-interest mailing list