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

Grid and Maximum String Length

1 Answer 772 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 22 Feb 2017, 12:38 PM

I have a grid on a page. One of the columns is for a person's middle initial. In my C# code, I have it defined as follows:

        [StringLength(1, ErrorMessage = "The middle initial cannot exceed 1 character")]<br>        [Display(Name = "Middle")]<br>        public string MiddleInitial { get; set; }<br>

 

In the grid, if I enter something like "LLL" for the middle initial, I get a error in the grid telling me I've enter too many characters. This is what I would expect. However, if I enter something like " L" (notice the space before the L), the grid gives me no errors. But, then, when the row is saved I get a server validation error. because of too many characters.

Why isn't the Kendo Grid handling the second scenerio correctly, and how can I work around this?

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 24 Feb 2017, 07:38 AM
Hello Randy,

This is the default behavior of the built-in Kendo UI Validator-it doesn't count the  spaces as characters from the max length limit. You can see this in the following demo:
Validator / Basic usage

In the first input, you can type in no more than 10 letters, but you can append as many  spaces as you want.

To add validation for this case, you can customize the built-in validator by following the instructions provided here:
Validation (see the instructions for adding a custom attribute and then extending the validator to apply it)

I hope this helps.

Regards,
Tsvetina
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or