gpt4 book ai didi

knockout-validation - 淘汰赛验证插件自定义错误消息

转载 作者:行者123 更新时间:2023-12-04 08:18:11 25 4
gpt4 key购买 nike

基于以下内容,我究竟如何设置回调以显示自定义错误消息而不是默认消息?

ko.validation.rules['exampleAsync'] = {
async: true, // the flag that says "Hey I'm Async!"
validator: function (val, otherVal, callBack) { // yes, you get a 'callback'

/* some logic here */

// hand my result back to the callback
callback( /* true or false */ );
// or if you want to specify a specific message
callback( /* { isValid: true, message: "Lorem Ipsum" } */ );
},
message: 'My default invalid message'
};

最佳答案

ko.validation.rules['exampleAsync'] = {
async: true,
validator: function (val, otherVal, callBack) {

// make an ajax call or something here to do your async validation
$.ajax({ type: 'post', url: 'some url', data: val, success: function (data) {
if (data.success) {
callback({ isValid: true, message: "yay it worked"});
} else {
callback({ isValid: false, message: data.message });
}
});
},
message: 'My default invalid message'
};

关于knockout-validation - 淘汰赛验证插件自定义错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12611878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com