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

How can I validate string maxLength when editing a cell?

10 Answers 3762 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oscar
Top achievements
Rank 1
Oscar asked on 13 Feb 2012, 06:03 PM
Hello forum:
I'm new in Kendo UI and this is my first question: How can I validate maxLength in a cell of grid?
Kind regards,
Oscar

10 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Feb 2012, 01:42 PM
Hello Oscar,

You may add additional validation rules which to be executed during Grid editing through the model definition. For example:

new kendo.data.DataSource({
    //.....
    schema: {
        model: {
            id: "ProductID",
            fields: {                  
                //....
                ProductName: {
                    validation: {
                        required: true,
                        maxlength:
                            function(input) { 
                                if (input.val().length > 5) {
                                   input.attr("data-maxlength-msg", "Max length is 5");
                                   return false;
                                }                                   
                                return true;
                            }
                    }
                }
            }
        }
    }
});


Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Oscar
Top achievements
Rank 1
answered on 15 Feb 2012, 11:07 AM
Hello Rosen:
Thanks for your help.
One last question:
Is there a way to set the attribute maxLength of the <input> to specify the maximum number of characters allowed for editing that cell?
1
Accepted
Rosen
Telerik team
answered on 15 Feb 2012, 01:53 PM
Hello Oscar,

You should use Grid's edit event to apply the attribute to the appropriate input.

$("#grid").kendoGrid({
     dataSource: dataSource,
     editable: true,
     edit: function(e) {
         e.container.find("input[name=ProductName]").attr("maxlength", 5);
     },
     //....
 });


All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
jc mag
Top achievements
Rank 1
answered on 29 Feb 2012, 08:02 PM
It would be great to have the maxLength validation function built in your datasource component ;)
0
Loganathan
Top achievements
Rank 1
answered on 18 Apr 2012, 10:30 AM

Hi
i have problem similar like this,

How can I validate dropdownlist when editing a cell?



Help me!
0
Matthew
Top achievements
Rank 1
answered on 27 Dec 2012, 03:44 PM
In reference to this solution:
new kendo.data.DataSource({
    //.....
    schema: {
        model: {
            id: "ProductID",
            fields: {                  
                //....
                ProductName: {
                    validation: {
                        required: true,
                        maxlength:
                            function(input) { 
                                if (input.val().length > 5) {
                                   input.attr("data-maxlength-msg","Max length is 5");
                                   return false;
                                }                                   
                                return true;
                            }
                    }
                }
            }
        }
    }
});


It appears the maxlength function is being executed for every input element within the table row (in edit mode), instead of just the input for the field specified.

Is this the intended behavior?

Regards,

Matthew Sweeney
0
Sampath
Top achievements
Rank 1
answered on 03 Nov 2014, 11:00 AM
hi,

how can I achieve the same functionality if I were to use ASP.NET MVC (Razor syntax). Can you please provide that as well? 
0
Rosen
Telerik team
answered on 05 Nov 2014, 08:22 AM
Hi Sampath,

Information on how to implement custom validation using Kendo UI Validator in the context of ASP.NET MVC can be found in this help article.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
asad
Top achievements
Rank 1
answered on 16 Jul 2016, 09:21 AM
dear Rosen i have a Time Format like this 234:00 how i validate it when i enter more then 3 value before colon its cant enter and same as i enter 2 value before colon its cant enter in kendo grid field 
0
Rosen
Telerik team
answered on 18 Jul 2016, 07:02 AM
Hi asad,

I'm afraid I did not understood your question. In case you need a custom validation rule you should check this help article on how to implement such. Otherwise, you should open a separate support request in which to provide as much details about what is the actual problem as possible. Also a simplified test page which to demonstrate the issue  you are having will be appreciated.

Regards,
Rosen
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Oscar
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Oscar
Top achievements
Rank 1
jc mag
Top achievements
Rank 1
Loganathan
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Sampath
Top achievements
Rank 1
asad
Top achievements
Rank 1
Share this question
or