[Dojo-interest] Question about submit form
Siqi
siqi.zhong at gmail.com
Sun Aug 21 22:33:05 EDT 2011
zhang wrote:
>
> 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.
>
RE Q1: If I recollect correctly, there's no 'onSubmit' event or method for a
dijit.form.Button. So I think you should bind your callback
'questionSubmitClicked' to the 'onSubmit' method of your form 'questionForm'
rather than the button 'btnQuestion'.
RE Q2: You can try again after fixing the first issue.
Thanks,
Siqi
--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Question-about-submit-form-tp3270320p3273921.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
More information about the Dojo-interest
mailing list