我的剑道组有一个Kendo Popup编辑器。
如果用户点击更新时出现验证错误,我想执行jquery操作。
我已经使用onSave函数执行此操作:
function onSave(e) {
alert("you've clicked save")
}
但是,只有在字段上没有验证错误消息时才会调用该函数。当用户单击“保存”并且有验证消息时,如何引发功能。
由于
答案 0 :(得分:0)
我创建了这个this.。
本DEMO有:
save
event kendogrid 以下是代码段:
$("#grid").kendoGrid({
....
...
save: function(e) {
alert('Popup form save event fired! Now validate the popup form for proper data');
if (validateForm()) {//if form validation is successful
alert("Form validation is successful");
e.preventDefault();//This code line must be removed for successful form submission. It is kept here only for demonstration purpose
}
else {
//Form validation failed
e.preventDefault();//So prevent form submission
}
}
....
...
function validateForm()
{
var validator = $("#popupForm").kendoValidator({
rules: {
minlength: function(input) {
//only address will be validated
if (input.is("[name=address]")) {
if (input.val().length < 4)
return false;
}
return true;
},
checkcity: function(input) {
//only city will be validated
if (input.is("[name=city]")) {
if (input.val() != "ABC")
return false;
}
return true;
}
},
messages: {
minlength: "Min length required is 4",
checkcity: "City name must be ABC"
}
}).data("kendoValidator");
if (validator.validate()) {
return true;
}
else {
alert("Oops! There is invalid data in the form.\n"+validator.errors());
return false;
}
}