无法解散DOJO dijit.form.form

无法解散DOJO dijit.form.form,dojo,Dojo,我有一个表单,我想禁用整个表单点击一个按钮,请看这个代码 <div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data" action="" method=""> <table> <input type="text" id="name" name="name" r

我有一个表单,我想禁用整个表单点击一个按钮,请看这个代码

 <div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data"
        action="" method="">

             <table>
                        <input type="text" id="name" name="name" required="true" dojoType="dijit.form.ValidationTextBox"
                        <input type="text" id="dob" name="dob" dojoType="dijit.form.DateTextBox"
            </table>
            <button dojoType="dijit.form.Button" type=button onClick="console.log(myForm.getValues())">
                Get Values from form!
            </button>
            <button dojoType="dijit.form.Button" type="submit" name="submitButton"
            value="Submit">
                Submit
            </button>
            <button dojoType="dijit.form.Button" type="reset">
                Reset
            </button>

   <button dojoType="dijit.form.Button" onClick="callMe()">
               Disable IT
            </button>

        </div>

Dijit表单没有属性“disabled”,但您必须覆盖onSubmit事件:

dijit.byId('myForm').onSubmit = function () {
     // If we return false here, the form will not be submitted.
     return myMagicEnabledFlag;
};

请注意,您不能使用dojo.connect,因为您必须修改事件的返回值,而不仅仅是连接到它。

要禁用整个表单元素,请使用dijit表单的“getChildren()”函数,该函数将返回对应表单的所有字段小部件的数组。然后,您需要禁用该数组的小部件。见以下示例:-

dijit.byId('myForm').onSubmit = function () {
     var widgets = dijit.byId('myForm').getChildren();
     for(var i=0;i<widgets.length;i++) {
        widgets[i].set('disabled', true);
     }
     //if you need to prevent the form submission & just disable, return false, 
     //else ignore the following return stmt
     return false; 
};
dijit.byId('myForm').onSubmit=function(){
var widgets=dijit.byId('myForm').getChildren();
对于(var i=0;i
dijit.byId('myForm').onSubmit = function () {
     var widgets = dijit.byId('myForm').getChildren();
     for(var i=0;i<widgets.length;i++) {
        widgets[i].set('disabled', true);
     }
     //if you need to prevent the form submission & just disable, return false, 
     //else ignore the following return stmt
     return false; 
};