【发布时间】:2018-12-04 17:55:33
【问题描述】:
我在应用程序中出现验证消息时遇到问题。这是应用程序演示:
我已尝试添加验证配置。这直接来自docs。
app.run(function(formlyValidationMessages) {
formlyValidationMessages.messages.required = 'to.label + " is required"';
formlyValidationMessages.messages.max = '"The max value allowed is " + to.max';
formlyValidationMessages.messages.min = '"The min value allowed is " + to.min';
formlyValidationMessages.addTemplateOptionValueMessage('pattern', 'patternValidationMessage', '', '', 'Invalid Input');
});
我在我的字段上设置了最小/最大值。该字段确实得到了正确验证,但消息仍然没有出现。
pattern/patternValidationMessage 和 validation (config) 函数都不适用于该领域。他们什么都不做,即使有一个有效的模式,该字段仍然显示它是无效的(红色突出显示)。
{
key: 'cooldown',
type: 'input',
templateOptions: {
type: 'number',
label: 'Cooldown (in seconds)',
min : 0,
max : 600,
required: true,
//pattern: /^[0-9]+$/,
//patternValidationMessage: '"Needs to match " + options.templateOptions.pattern'
},
defaultValue: 30,
//validation: {
// messages: {
// required: function ($viewValue, $modelValue, scope) {
// return scope.to.label + ' is required';
// }
// }
//},
}
我能否获得一些关于为什么该消息不会出现的提示?
【问题讨论】:
标签: javascript angularjs validation angular-formly