This is a migrated thread and some comments may be shown as answers.

How to set maxlength for inline edit cell

4 Answers 776 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Suresh
Top achievements
Rank 1
Veteran
Suresh asked on 15 Jul 2020, 01:18 AM

Below the snippet i was trying.

columns.Bound(c => c.OrderNumber).Title("OrderNumber").                                   

                                        .EditorTemplateName("_EditTextBox").EditorViewData(new { maxLength = 3})

Any help or pointers ?

4 Answers, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 16 Jul 2020, 11:58 AM

Hello, Suresh,

You can use DataAnnotation attributes. The Kendo UI Validator creates validation rules based on the unobtrusive HTML attributes. Those unobtrusive attributes are generated by ASP.NET MVC, based on the DataAnnotations applied to the Model properties. Here is an example:

[StringLength(3, ErrorMessage = "Name cannot be longer than 3 characters.")]
public string ProductName { get; set; }
You can find more information about Kendo validation in the following article:

As per the EditorViewData, this option has to be used only when you would like to pass additional data to the editor template. In the current case, you would have access to a variable "maxLength" in the editor template via the ViewData. It will not apply any validation.

Let me know if further assistance is needed.

Kind Regards,
Anton Mironov
Progress Telerik

0
Suresh
Top achievements
Rank 1
Veteran
answered on 18 Jul 2020, 05:06 PM

Thank You Anton!

Adding data annotations helps with validation .But , what i was looking was to prevent the user from entering characters more than the limit , like we have the maxlength for TextBox controls.

Added a editor template like -@Html.Kendo().TextBoxFor(x => x).HtmlAttributes(new { maxLength = ViewData["maxLength"] })
and binding the same as editor template in grid- EditorTemplateName("_EditTextBox").EditorViewData(new { maxlength = 50 });

This prevents the user from entering more than 50 characters in grid incell edit mode .

Its working but not sure if it's the right approach.

0
Accepted
Anton Mironov
Telerik team
answered on 20 Jul 2020, 03:01 PM

Hi, Suresh,

The approach that you have undertaken is the recommended one. Indeed, the data annotations will be used solely for validation. However, if you would like to restrict the user from entering more than a certain number of characters, the maxLength attribute has to be set on the editor directly.

Regards,
Anton Mironov
Progress Telerik

0
Suresh
Top achievements
Rank 1
Veteran
answered on 20 Jul 2020, 03:05 PM
Thank You Anton !
Tags
Grid
Asked by
Suresh
Top achievements
Rank 1
Veteran
Answers by
Anton Mironov
Telerik team
Suresh
Top achievements
Rank 1
Veteran
Share this question
or