如何在页面首次加载时停止验证?我希望在文本框被编辑或具有焦点并失去焦点时触发验证,而不是在页面首次加载时触发。
我的加载代码:
$(document).ready(function () {
ko.validation.configure({
registerExtenders: true,
messagesOnModified: false,
decorateElement: true,
errorClass: 'error',
insertMessages: true,
parseInputAttributes: true,
messageTemplate: 'customMessageTemplate'
});
ko.applyBindings(new UserAccount(initdata), $("#UserAccount").get(0));
});
function UserAccount(data) {
var self = this;
self.UserName = ko.observable(data.UserName).extend({ required: { message: "Username is required" }, minlength: 6, maxLength: 12 });
self.Password = ko.observable(data.Password).extend({ required: { message: "Password is required" }, minlength: 6, maxLength: 12 });
self.Firstname = ko.observable(data.Firstname).extend({ required: { message: "Firstname is required" }, minlength: 6, maxLength: 40 });
...... other code .....
}
我一直在尝试对此进行研究,但似乎没有任何效果。我认为 ko.validation.configuration 'messagesOnModified: false' 中可能有一些东西(我尝试了 true,并将其全部删除)。