Custom validation on pop-up edit template

2 posts, 0 answers
  1. Dustin
    Dustin avatar
    7 posts
    Member since:
    May 2015

    Posted 31 Mar Link to this post

    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

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 04 Apr Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top