我正在使用 Dojo-1.9.1 并尝试为我们的应用程序构建模板化表单。当表单验证失败时,我正在使用noty显示错误警报。当我像这样在模板中直接使用时,调用 noty 有效:
<form data-dojo-attach-point="formNode" data-dojo-type="dijit/form/Form"
enctype="application/x-www-form-urlencoded" action=${submitUrl} method="post">
<script type="dojo/on" data-dojo-event="submit">
if(!this.validate()){
noty({
text: '${messages.invalidForm}',
type: 'error',
modal: true,
timeout: 2000, // false, to wait for user click
closeWith: ['click', 'hover'], // ['click', 'button', 'hover']
}); // works
return false;
}
return true;
</script>
<!-- other fields -->
</form>
然而,在 onSubmit 方法中创建时,noty 无法显示,如下所示:
<form data-dojo-attach-point="formNode" data-dojo-type="dijit/form/Form"
enctype="application/x-www-form-urlencoded" action=${submitUrl} method="post" data-dojo-attach-event="onSubmit:handleSubmit">
</form>
//Within the template.js
handleSubmit: function() {
if(!this.formNode.validate()) {
noty({text:...}); //fails to come up
return false;
}
return true;
}
dojoConfig:
// ... preceding dojo packages
{ name: "jquery", location: "lib", main: "jquery-1.10.2.min" },
{ name: "noty", location: "lib", main: "jquery.noty.packaged.min" }
它也无法在控制台中出现。我想我已经正确地对库进行了 AMD 处理,因为它首先可以工作。谁能指出我的实现中缺少的任何链接。谢谢。