【问题标题】:Change knockout validationMessages globally for all pages全局更改所有页面的淘汰验证消息
【发布时间】:2015-12-29 15:56:11
【问题描述】:

我希望所有页面的输入验证消息都显示为红色。 我该怎么做才能让它在全球范围内发挥作用?

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
        }
    };

【问题讨论】:

标签: javascript css knockout.js knockout-validation


【解决方案1】:

插入的错误消息具有指定的类,默认情况下为validationMessage。如果您想全局更改样式,只需为该类设置一些 css 规则就足够了。

.validationMessage
{
    color: red;
}

当然,您也可以选择覆盖默认消息类别。

ko.validation.init({
    errorMessageClass: 'my-error-class'
});

【讨论】:

  • 我正在使用默认验证(输入下方显示一条消息)。我只想一次将所有页面的文本颜色从黑色更改为红色。这个“ko.validation.rules.required.message”应该放在哪里?
  • 哦,哎呀,我误读了您的问题以更改消息的措辞,而不是样式。有机会我会更新的。
猜你喜欢
  • 2017-02-19
  • 2017-09-26
  • 2015-01-08
  • 2014-03-15
  • 1970-01-01
  • 2014-07-07
  • 2020-04-22
  • 2014-05-28
  • 2014-12-04
相关资源
最近更新 更多