剑道弹出编辑器,验证错误消息



我的剑道组有一个剑道弹出编辑器。

如果用户单击更新时出现验证错误,我想执行 jquery 操作。

我已经使用 onSave 函数来执行此操作:

function onSave(e) {
        alert("you've clicked save")
}

但是,仅当字段上没有验证错误消息时,才会调用该函数。当用户单击保存并且有验证消息时,如何引发函数。

谢谢

我创建了这个演示

此演示具有:

  • 自定义弹出编辑器窗体
  • 自定义剑道验证程序,用于验证表单上的自定义规则领域
  • 检查表单中是否有有效数据save事件 kendogrid
  • 在警报中显示 valdation 错误消息并阻止表单提交

以下是代码片段:

$("#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;
  }
}

最新更新