嗨我有一个问题与表单验证与dojo的表单dijit其中 我有两个或多个选项卡的形式。如果我有一个字段在选项卡 2上无效,但我在验证时(通过按提交/确定按钮)将其定位在tab1上,则验证方法会执行,但无法找到错误的dijit(切换到正确的选项卡)并专注于此。 invalidMessage出现,但位于窗口的左上角,而不是它应该在的位置的 。 有没有办法实现这个或解决方法适用于dojo 1.6?您可以提供的任何信息将不胜感激,谢谢。Dojo表单验证横跨标签
0
A
回答
1
如果你正在使用dijit.form.Form(它看起来像你),我认为最简单的方法是覆盖窗体的validate函数。看看在dijit.form.Form原来的验证函数的定义(在_FormMixin.js):
validate: function(){
// summary:
// returns if the form is valid - same as isValid - but
// provides a few additional (ui-specific) features.
// 1 - it will highlight any sub-widgets that are not
// valid
// 2 - it will call focus() on the first invalid
// sub-widget
var didFocus = false;
return dojo.every(dojo.map(this.getDescendants(), function(widget){
// Need to set this so that "required" widgets get their
// state set.
widget._hasBeenBlurred = true;
var valid = widget.disabled || !widget.validate || widget.validate();
if(!valid && !didFocus){
// Set focus of the first non-valid widget
dojo.window.scrollIntoView(widget.containerNode || widget.domNode);
widget.focus();
didFocus = true;
}
return valid;
}), function(item){ return item; });
},
你可以围绕if(!valid && !didFocus){
条件改为查找验证失败的部件是哪个选项卡,并切换到它。
0
这适用于我。它只是检查父母是否是一个标签(有点丑陋,所以建议是受欢迎的),如果是,获取其父母并激活标签。 它扩展了scrollIntoView,因为这对我来说看起来是正确的功能。这意味着如果您在某个选项卡上将小部件滚动到视图中,该选项卡会自动激活。
只要确保此代码在某处运行。
define([
"dojo/_base/window",
"dojo/aspect",
"dojo/dom",
"dojo/dom-class",
"dojo/window",
"dijit/registry"
], function (baseWindow, aspect, dom, domClass, win, registry) {
//extend scrollintoview to make sure, if the element resides on a tab, the tab is activated first.
aspect.around(win, "scrollIntoView", function (originalScrollIntoView) {
return function (node, pos) {
node = dom.byId(node);
var doc = node.ownerDocument || baseWindow.doc,
body = baseWindow.body(doc),
html = doc.documentElement || body.parentNode;
if (node == body || node == html) { return; }
var widget = registry.byNode(node.domNode || node);
if (typeof widget != "undefined" && widget != null) {
if (typeof widget.getParent != "undefined") {
var par = widget.getParent();
if (domClass.contains(node.domNode || node, 'dijitTabPane')) {
if (typeof par.selectChild != "undefined") {
try {
par.selectChild(widget);
} catch (e) { }
return;
}
}
if (domClass.contains(par.domNode, 'dijitTabPane')) {
this.scrollIntoView(par.domNode);
}
}
}
}
return originalScrollIntoView(node, pos);
});
});
相关问题
- 1. Dojo:单击标签
- 2. ASP.net mvc表单验证内Jquery标签
- 3. CodeIgniter表单验证匹配标签
- 4. 单独验证Div标签
- 5. Dojo DataGrid验证
- 6. 跨多个组件的表单验证
- 7. 跨子域的表单身份验证
- 8. 表单身份验证跨Windows身份验证
- 9. html5验证表单标记
- 10. ASP.NET验证标签
- 11. 验证HTML缺少div,表标签?
- 12. 验证错误与表格标签
- 13. 显示验证标签时,表单中标签元素的CSS错误
- 14. 在验证摘要错误列表中使用标签标签?
- 15. 动态验证多个Google表单标签
- 16. 没有任何表单标签的Angularjs验证
- 17. 表单提交,验证并在新标签中打开链接
- 18. 使用Dojo的自定义表单验证
- 19. struts2 dojo标签显示在struts表单标签上方为什么会这样?
- 20. 验证标签文本
- 21. Strut2验证 - 选择标签
- 22. 系统HTML标签验证
- 23. 标签长度的验证
- 24. 跳过jQuery验证标签
- 25. git验证信任标签
- 26. 验证/清除使用Dojo
- 27. 在Dojo中验证SimpleTextArea
- 28. 表单验证
- 29. 表单验证
- 30. 表单验证