New to Kendo UI for jQuery? Download free 30-day trial

Show Validation Summary in Grid Popup Editing Window

Environment

Product Progress® Kendo UI® Grid for jQuery

Description

How can I display the validation summary instead of tooltips in the Grid popup edit window?

Solution

To achieve the desired scenario:

  1. Add an edit event handler to generate the Validation summary and append it to a predefined HTML element in your popup editing window.
  2. Hide the validation tooltip with CSS.
   <div id="grid"></div>
      <script>
        $(document).ready(function () {
          var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service",
              dataSource = new kendo.data.DataSource({
                transport: {
                  read:  {
                    url: crudServiceBaseUrl + "/Products",
                    dataType: "jsonp"
                  },
                  update: {
                    url: crudServiceBaseUrl + "/Products/Update",
                    dataType: "jsonp"
                  },
                  destroy: {
                    url: crudServiceBaseUrl + "/Products/Destroy",
                    dataType: "jsonp"
                  },
                  create: {
                    url: crudServiceBaseUrl + "/Products/Create",
                    dataType: "jsonp"
                  },
                  parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                      return {models: kendo.stringify(options.models)};
                    }
                  }
                },
                batch: true,
                pageSize: 20,
                schema: {
                  model: {
                    id: "ProductID",
                    fields: {
                      ProductID: { editable: false, nullable: true },
                      ProductName: { validation: { required: true } },
                      UnitPrice: { type: "number", validation: { required: true, min: 1} },
                      Discontinued: { type: "boolean" },
                      UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                    }
                  }
                }
              });

          $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            height: 550,
            toolbar: ["create"],
            columns: [
              { field:"ProductName", title: "Product Name" },
              { field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "120px" },
              { field: "UnitsInStock", title:"Units In Stock", width: "120px" },
              { field: "Discontinued", width: "120px"},
              { command: ["edit", "destroy"], title: "&nbsp;", width: "250px" }],
            editable: "popup",
            edit: function(e) {
              var validator = e.container.find(".k-edit-form-container").data("kendoValidator");
              e.container.prepend("<span id='errors' style='color:red;'></span>")
              validator.bind("validate", function (e) {
                var errors = this.errors();
                if (errors.length) {
                  var html = "<ul>";
                  for (var i = 0; i < errors.length; i++) {
                    html += "<li>" + errors[i] + "</li>";
                  }
                  html += "</ul>";
                  $("#errors").html($(html));
                }
              });
            }
          });
        });
      </script>
    <style>
      .k-invalid-msg {
        display: none;
      }
    </style>

See Also

In this article