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

Grid Validation confusion!

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ratan
Top achievements
Rank 1
Ratan asked on 10 Apr 2016, 02:19 PM

Hi, 

 

I am  new to Kendo and I am facing a very confusing problem that i cant solve.

 

I have a grid which contains 5 columns like so - RoleName, Description, isActive, isDeleted, Action.

Now i have validation just on the RoleName Column.

 

My issue is, I should not let the user Input duplicate RoleName on edit or on creating a new record. For example, RoleName = Admin already exists on the grid and when the user creates a new record he shouldn't be able to enter Admin again, i got this part to work however when the user edits the already existing row which contains "Admin" as the rolename and changes isActive, the validation fires again telling Admin already exists and i cant edit that row. How do i fix this?

 

fields: {
                            Id: { type: "number", editable: false },
                            RoleName: {
                                type: "string",
                                validation: {
                                    required: true,
                                    validateOnBlur: false,
                                    rolenameValidation: function (input) {
                                        if (input.is("[name='RoleName']") && input.val() !== "" && NetAppAssetRecoveryRoleAdminMethods.IfRoleNameExists(input.val())) {
                                            input.attr("data-rolenameValidation-msg", "Role Name already exists");
                                            return false;
                                        }
                                        else if (NetAppAssetRecoveryRoleAdminMethods.IfRoleNameExists(input.val()) == undefined)
                                        {
                                            input.attr("data-rolenameValidation-msg", "Role Name can contain only characters");
                                            return false;
                                        }
                                        return true;
                                    }
                                }
                            },.....
...............
...............

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Apr 2016, 06:27 AM
Hi Ratan,

The behavior that you are describing is expected, because the validation will fire again when you change another field in that row and when that happens, your IfRoleNameExists method returns true. One thing that you can try is to include the ID of that row as a parameter and skip that ID while checking the items.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Ratan
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or