When the user types the input in the dojotype="dijit.form.DateTextBox" as "Abcd" its shows the value entered is not valid.but its allowing the user to submit the form without any issues.
I wanna disable the submit button if invalidmessage attribute of datetextbox shown up.
我正在尝试使用以下代码实现该功能;仍然我无法实现功能datatextbox.on没有触发。我是dojo的新手.Kindly帮助我。
function validateSubmit(){
alert('validate');
var dateTextBox = dijit.byId("fromDedDate").get('value');
alert('dateTextBox value '+dateTextBox);
var dateTextBoxId = dijit.byId("fromDedDate");
alert('dateTextBox id '+dateTextBoxId);
var submitButton = document.getElementById('search');
alert('submitButton '+submitButton);
dateTextBox.on('change', function(e){
var result = dateTextBox.validate();
alert('result');
});
}
<form:input
path="deductionSearchFilter.deductionDateFrom" size='20'
id="fromDedDate" dojotype="dijit.form.DateTextBox"
onchange="dijit.byId('toDedDate').constraints.min = arguments[0];"
size="10" style="width: 114"
title="A single Deduction Date can be entered in the From/To fields or a range of Deduction Dates can be entered to search multiple days." />
<td align='center'><input id="search" onclick="validateSubmit();" type="submit" name="Search"
value="Search" class="button"
title="View the results of search" />
</td>
答案 0 :(得分:0)
您可以从dateTextBox连接到change事件并挂钩处理程序。您应该注意,当用户按下回车键时,这不会阻止表单提交。
var dateTextBox = registry.byId('dateTextBox');
var submitButton = registry.byId('submitButton');
dateTextBox.on('change', function(e){
var result = dateTextBox.validate();
submitButton.set('disabled', result);
});
如果您想要更好地控制表单,我建议您将表单元素包装在dijit / form / Form中。请查看参考:http://dojotoolkit.org/reference-guide/1.10/dijit/form/Form.html以获取示例。