![](/img/trans.png)
[英]Angular-JS: Multiple error messages on single field based on numeric or alphanumeric patterns
[英]Multiple error messages, based on another field
我嘗試動態生成錯誤消息:
window.Parsley.addValidator('validatorName', {
requirementType: 'string',
validateString: function (value) {
return validateField(value);
},
messages: {
en: 'Invalid ' + someValue
}
});
但它並沒有改變,它將someValue
設置為它在頁面中設置的第一個值。
如何根據此值動態更改消息?
我會將獲取動態值的邏輯放入 function,然后在您的驗證器中調用該 function。
function getValue() {
let returnValue = "";
// logic to get the value of someValue
returnValue = someValue
return returnValue;
}
window.Parsley.addValidator('validatorName', {
requirementType: 'string',
validateString: function (value) {
return validateField(value);
},
messages: {
en: 'Invalid ' + getValue()
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.