我有一个表单,我想要点击一个按钮禁用整个表单,请参阅此代码
<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>
我编写了一个函数callMe来禁用此
function callMe()
{
dijit.byId('myForm').disabled=true;
}
答案 0 :(得分:2)
Dijit表单没有“禁用”属性,而是你必须覆盖onSubmit事件:
dijit.byId('myForm').onSubmit = function () {
// If we return false here, the form will not be submitted.
return myMagicEnabledFlag;
};
请注意,您不能使用dojo.connect,因为您必须修改事件的返回值,而不仅仅是连接到它。
答案 1 :(得分:0)
要禁用整个表单元素,请使用&#34; getChildren()&#34; dijit表单的函数,它将返回相应表单的所有字段小部件的数组。然后,您需要禁用该数组的小部件。见下面的样本: -
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;
};