我从不希望在视图上显示任何错误消息(我使用toastr来显示由敲除验证生成的错误)。在我的代码中,我正在使用:insertMessages:false。这会抑制错误,除非用户在必填字段中输入数据,删除该数据,然后从控件中删除。当用户选中输入控件时,我无法弄清楚如何隐藏任何错误消息。这是我的代码摘录 -
视图模型 -
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 }" />
答案 0 :(得分:1)
尝试将输入包装在像div这样的容器中,并将validationOptions应用于此。
<div data-bind="validationOptions: { insertMessages: false }"><input data-bind="value: LCAmount" /></div>