开发者

Unable to Disbale the DOJO dijit.form.Form

I have a Form and i want to disable the entire form on click of a Button ,please see this code

 <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开发者_Go百科 dojoType="dijit.form.Button" type="reset">
                Reset
            </button>

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

        </div>

I have written a function callMe to disable this

function callMe()
{

dijit.byId('myForm').disabled=true;
}


Dijit forms do not have a property "disabled", but rather you have to overwrite the onSubmit event:

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

Note that you cannot use dojo.connect as you have to modify the return value of the event and not just connect to it.


For disabling the entire form elements, use the "getChildren()" function of the dijit form, which would return the array of all the field widgets of that corresponding form. Then, you need to disable the widgets of that array. See below sample:-

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; 
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜