嗨我有一個問題與表單驗證與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. PHP標籤 - 表單驗證
- 2. Dojo:單擊標籤
- 3. CodeIgniter表單驗證多語言標籤
- 4. jQuery驗證 - 與表單標籤
- 5. 帶標籤的HTML5驗證表單
- 6. fuelux標籤,嚮導表單驗證
- 7. ASP.net mvc表單驗證內Jquery標籤
- 8. CodeIgniter表單驗證匹配標籤
- 9. Dojo表格驗證表單標記中的特定項目
- 10. 單獨驗證Div標籤
- 11. Dojo DataGrid驗證
- 12. Dojo驗證
- 13. 跨多個組件的表單驗證
- 14. 跨子域的表單身份驗證
- 15. 表單身份驗證跨Windows身份驗證
- 16. html5驗證表單標記
- 17. 驗證標籤頁?
- 18. ASP.NET驗證標籤
- 19. 驗證HTML缺少div,表標籤?
- 20. 驗證錯誤與表格標籤
- 21. 顯示驗證標籤時,表單中標籤元素的CSS錯誤
- 22. 表單驗證未驗證
- 23. 跨瀏覽器標籤的JHipster JWT身份驗證
- 24. 在驗證摘要錯誤列表中使用標籤標籤?
- 25. 使用離子滾動標籤時的表單驗證錯誤
- 26. 提交表單標籤中的驗證功能
- 27. 使用註釋和輸入標籤Struts2表單驗證
- 28. 動態驗證多個Google表單標籤
- 29. 沒有任何表單標籤的Angularjs驗證
- 30. 如何驗證沒有表單標籤的字段?