全局更改所有页面的敲除验证消息
Change knockout validationMessages globally for all pages
我希望所有页面的输入验证消息都显示为红色。
我该怎么做才能在全球范围内运作?
knockout.validation.debug.js有这段代码
var defaults = {
registerExtenders: true,
messagesOnModified: true,
errorsAsTitle: true, // enables/disables showing of errors as title attribute of the target element.
errorsAsTitleOnModified: false, // shows the error when hovering the input field (decorateElement must be true)
messageTemplate: null,
insertMessages: true, // automatically inserts validation messages as <span></span>
parseInputAttributes: false, // parses the HTML5 validation attribute from a form element and adds that to the object
writeInputAttributes: false, // adds HTML5 input validation attributes to form elements that ko observable's are bound to
decorateInputElement: false, // false to keep backward compatibility
decorateElementOnModified: true,// true to keep backward compatibility
errorClass: null, // single class for error message and element
errorElementClass: 'validationElement', // class to decorate error element
errorMessageClass: 'validationMessage', // class to decorate error message
allowHtmlMessages: false, // allows HTML in validation messages
grouping: {
deep: false, //by default grouping is shallow
observable: true, //and using observables
live: false //react to changes to observableArrays if observable === true
},
validate: {
// throttle: 10
}
};
插入的错误消息默认分配 class,validationMessage
。如果你想全局更改样式,只需为 class 设置一些 css 规则就足够了。
.validationMessage
{
color: red;
}
当然,您也可以选择覆盖默认消息 class。
ko.validation.init({
errorMessageClass: 'my-error-class'
});
我希望所有页面的输入验证消息都显示为红色。 我该怎么做才能在全球范围内运作?
knockout.validation.debug.js有这段代码
var defaults = {
registerExtenders: true,
messagesOnModified: true,
errorsAsTitle: true, // enables/disables showing of errors as title attribute of the target element.
errorsAsTitleOnModified: false, // shows the error when hovering the input field (decorateElement must be true)
messageTemplate: null,
insertMessages: true, // automatically inserts validation messages as <span></span>
parseInputAttributes: false, // parses the HTML5 validation attribute from a form element and adds that to the object
writeInputAttributes: false, // adds HTML5 input validation attributes to form elements that ko observable's are bound to
decorateInputElement: false, // false to keep backward compatibility
decorateElementOnModified: true,// true to keep backward compatibility
errorClass: null, // single class for error message and element
errorElementClass: 'validationElement', // class to decorate error element
errorMessageClass: 'validationMessage', // class to decorate error message
allowHtmlMessages: false, // allows HTML in validation messages
grouping: {
deep: false, //by default grouping is shallow
observable: true, //and using observables
live: false //react to changes to observableArrays if observable === true
},
validate: {
// throttle: 10
}
};
插入的错误消息默认分配 class,validationMessage
。如果你想全局更改样式,只需为 class 设置一些 css 规则就足够了。
.validationMessage
{
color: red;
}
当然,您也可以选择覆盖默认消息 class。
ko.validation.init({
errorMessageClass: 'my-error-class'
});