How to Add validation inside the kendo grid.

1 Answer 317 Views
Grid
Rohendra
Top achievements
Rank 1
Rohendra asked on 17 Aug 2023, 05:42 AM

I have Kendo Grid i need to add validation on innner textbox on updating a row.

I am using code like that.

 

@html.kendo()

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 21 Aug 2023, 10:06 AM

Hi Rohendra,

Thank you for the details provided.

In order to achieve the desired behavior, I would recommend using the approach from the following demo:

In the demo above, the ProductName column has a validation rule to start with a capital letter:

 $(document).ready( function () {
        $.extend(true, kendo.ui.validator, {
            rules: { // custom rules
                productnamevalidation: function (input, params) {
                    if (input.is("[name='ProductName']") && input.val() != "") {
                        input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");
                        return /^[A-Z]/.test(input.val());
                    }

                    return true;
                }
            },
            messages: { //custom rules messages
                productnamevalidation: function (input) {
                    // return the message text
                    return input.attr("data-val-productnamevalidation");
                }
            }
        });
    });
Make the needed tests on your side:

  1. Open the demo.
  2. Edit a record.
  3. Change the ProductName value so it does not start with a capital letter.
  4. Observe the result.

I hope this achieves the desired result.

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Tags
Grid
Asked by
Rohendra
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or