0

I'm currently displaying a Kendo UI Grid in a modal. I've got a few custom validations hooked up which are working fine. When the modal's "Save" button is clicked, I need to be able to check whether the grid is currently in a valid or invalid state.

Since I'm only using custom validation, it's certainly possible for me to keep a running track of the errors and then check the error count upon the modal closing, but I was hoping the Kendo UI Grid kept up with this and exposed something easy like myGrid.isValid() or some such thing.

Derek Greer
  • 15,454
  • 5
  • 45
  • 52

2 Answers2

0

If you use web-api on server side call ModelState.IsValid

More about this

What you mean about custom validation?

If you using kendo custom validation like in this reference reference that way user cant enter wrong values in editor. But if you want IsValid option, that way you need to impliment kendo.validator. Define validation rools in your model and then call validate():

// attach a validator to the container and get a reference
var validatable = $("#myform").kendoValidator().data("kendoValidator");

$("#save").click(function() {
  //validate the input elements and check if there are any errors
  if (validatable.validate() === false) {
    // get the errors and write them out to the "errors" html container
    var errors = validatable.errors();
    $(errors).each(function() {
      $("#errors").html(this);
    });
  }
});

Validator in kendo docs

Community
  • 1
  • 1
layonez
  • 1,746
  • 1
  • 16
  • 20
0

You can use this code to accomplish what you want

let validatable;

$(document).ready(() => {
    validatable = $("#gridId").kendoValidator().data("kendoValidator");
})

function PostData() {
    if (validatable.validate()) {
        // save the grid data
    }
}
vcRobe
  • 1,671
  • 3
  • 17
  • 35