我所追求的是一个表单,在提交时,运行验证检查,并突出显示所有无效字段并添加工具提示.
我正在寻找像这样的东西:
dojo.forEach(dijit.byId('myForm')._invalidWidgets, function (thisWidget,index,array) {
thisWidget.displayMessage("normal invalid/empty message should go here, seems I should be calling something higher level than this");
});
Run Code Online (Sandbox Code Playgroud)
但是我不想深入挖掘,我想要做的就是触发当你从一个空的必填字段(感叹号图标和相应的无效/空消息)中跳出时触发的同类事物.也许我应该尝试解雇标签事件?
有人能指出我正确的方向吗?
是的,你是对的 - 你可以通过调用元素validate()上的函数来获得所有验证,突出显示,甚至专注于第一个无效字段dijit.form.Form.
这是一个将validate()调用添加到onSubmit事件的示例:
<head>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojo.form.Form");
dojo.require("dojo.form.ValidationTextBox");
dojo.require("dojo.form.Button");
// more includes here...
</script>
</head>
<body>
<form dojoType="dijit.form.Form" action="..." method="...">
<input dojoType="dijit.form.ValidationTextBox" trim="true" regExp="..." invalidMessage="Oops...">
<!-- // more form elemts here... -->
<button type="submit" dojoType="dijit.form.Button" ...>
Submit
</button>
<script type="dojo/method" event="onSubmit">
if (!this.validate()) {
alert("Form contains invalid data. Please correct....");
return false;
}
return true;
<script>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
希望,你觉得它很有帮助.
干杯.
后续: 这是一个输入字段的示例,可用于帮助提示用户预期的数据类型,并在验证失败时提醒他们:
<input type="text" id="EXT" name="EXT" value=""
maxLength="10"
dojoType="dijit.form.ValidationTextBox"
regExp="\d+?"
trim="true"
promptMessage="<p class='help'>Please your extension. (i.e. "1234")</p>"
invalidMessage="<p class='help'>The extension field should contain only numbers.</p>">
Run Code Online (Sandbox Code Playgroud)
这是一个声明性的例子.(我在下面的初步回复中拼错了.)
| 归档时间: |
|
| 查看次数: |
5888 次 |
| 最近记录: |