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

Custom validation on pop-up edit template

1 Answer 581 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dustin
Top achievements
Rank 1
Dustin asked on 31 Mar 2016, 03:10 PM

I have a grid that I am using the pop-up editing in. I am using a custom template with drop-downs. The drop-downs have an "Other" option that when selected shows a textbox that you can enter the "Other" details in. This was all in a regular form before I added it to a grid for entry. So I have code for custom validation that would validate these fields if they were showing that worked in a regular form. However, since moving them into the grid pop-up editor, the custom validation is not firing for some reason.

I'm unsure what to do, I have tried to hook the validator up to the grid like so:

$("#DeviceGrid").kendoValidator({
            rules: {
                otherrequired: function (input) {
                    if (input.is("[data-val-otherrequired]")) {
                        var iVal = input.val();
                        var pFld = $("[name='" + input.attr("data-val-otherrequired-parentfield") + "_input']");
 
                        if (input[0].id === "DevicePhoneNum") {
 
                            if (pFld.val().toLowerCase().indexOf("phone") >= 0 && iVal === "") {
                                return false;
                            }
                        }
 
                        if (pFld.val() === "Other" && iVal === "") {
                            return false;
                        }
                    }
                    return true;
                }
            },
            messages: {
                otherrequired: function (input) {
                    return input.attr("data-val-otherrequired");
                }
            },
            validateOnBlur: true
        });

 

But I'm not sure that this is even the correct way of going about it.

Any insight into this would be appreciated!

Thanks,

Dustin

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 04 Apr 2016, 11:54 AM

Hello Dustin,

 

Actually there is a default validator that is initialized for the Kendo UI Grid widget in order to validate the user input when a new record is added or an existing one is being edited. We suggest to use that validator and add the custom rules as demonstrated int the Grid / Custom validator editing demo.

 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Dustin
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or