我不希望任何錯誤消息出現在視圖上(我正在使用toastr來顯示基因敲除驗證生成的錯誤)。在我的代碼中,我正在使用:insertMessages:false。這可以抑制錯誤,除非用戶在必填字段中輸入數據,刪除該數據,然後退出該控件。當用戶退出輸入控件時,我無法弄清楚如何隱藏任何錯誤消息。這裏是我的代碼excerpts-基因敲除驗證 - 隱藏錯誤信息
viewmodel-
LCAmount: ko.observable(LCAmount).extend({ insertMessages: false, required: { message: 'LC Amount is Required' } })
var saveAll = function() {
try {
var goAhead = true;
var changes = false;
SaveFlag(true);
ko.utils.arrayForEach(LoanDetails(), function (item) {
if (item.LCAmount != '')
changes = true;
if (item.errors().length > 0) {
goAhead = false;
logError("Errors on form: " + item.errors(), item, true);
}
});
if (goAhead && changes && okStoSave) {
$.prompt("Are you sure you want to save? You will not be able to change your decision after it's been saved.", {
title: "Save?",
buttons: { "Save": true, "Cancel": false },
submit: function (e, v, m, f) {
if (v) {
response = saveUpdates(LoanDetails);
});
vm.clientNumber('');
vm.clientName('');
}
}
});
}
查看 -
<input data-bind="value: LCAmount, validationOptions: { insertMessages: false }" />
你可以創建一個小提琴演示你的問題? –