Jquery Select的淘汰验证
我的表单中有一些选择控件和输入框,它们是必填字段,我正在使用敲除验证来验证它们。我希望控件在提交或修改时突出显示(使用errorElementClass)。不幸的是,我的选择控件在页面首次加载时会高亮显示Jquery Select的淘汰验证,jquery,validation,knockout.js,Jquery,Validation,Knockout.js,我的表单中有一些选择控件和输入框,它们是必填字段,我正在使用敲除验证来验证它们。我希望控件在提交或修改时突出显示(使用errorElementClass)。不幸的是,我的选择控件在页面首次加载时会高亮显示 <div>Names <select data-bind="options: allNames, optionsValue: 'id', optionsText: 'name', value: names, optionsCaption:'Select Names'"
<div>Names
<select data-bind="options: allNames, optionsValue: 'id', optionsText: 'name', value: names, optionsCaption:'Select Names'"></select>
<button id="btnSubmit">Submit</div>
ko.validation.configure({
insertMessages: false,
messagesOnModified: true,
decorateElement: true,
errorElementClass: "input-validation-error",
deep: false,
enableErrorDetails: true
});
function ViewModel() {
var self = this;
self.names = ko.observable("").extend({
required: true
});
self.allNames = new ko.observableArray([]);
self.call = function () {
self.allNames.push({
id: 1,
name: "Adam"
});
self.allNames.push({
id: 2,
name: "Bert"
});
self.allNames.push({
id: 3,
name: "Keith"
});
self.allNames.push({
id: 4,
name: "Anna"
});
self.allNames.push({
id: 5,
name: "Andie"
});
}
}
self.errors = ko.validation.group(this);
vm = new ViewModel();
vm.call();
$("#btnSubmit").click(function () {
});
ko.applyBindings(vm);
}
刚刚将其更改为以下内容: self.names=ko.observable(未定义)。扩展({ 必填项:true
}); 你能更详细地描述一下这个问题吗?我已经修改了我的问题,希望能有所帮助。谢谢。很酷,我会看一看,但为了将来的参考,如果你可以显示一个简化的小提琴,显示问题以帮助更快地理解和调试,它会有100倍的帮助,仅供参考。仅供参考编辑我的问题并添加一个小提琴。我基本上希望元素在提交时突出显示,而不是在页面加载时突出显示。谢谢你的帮助!所以你不想在按下submit之前应用CSS?
.input-validation-error {
border-color:red !important;
border-style:solid !important;
border-width:1Px !important;
box-shadow: 0px 0px 2px red !important;
/*Add webkit box shadows for other browsers*/