Using grid validation in a form

1 posts, 0 answers
  1. Brad
    Brad avatar
    1 posts
    Member since:
    Jun 2011

    Posted 02 Aug 2012 Link to this post

    I am new to the Kendo UI so I may not know how best to phrase my question.  I have setup validation for my grid to be used during inline edits.  I would to use this same validation for a user form as well.  No one likes to code the same thing twice.  Any ideas of how I can do that?

    My validation for the grid:

    var cityCodesModel = {
        id: "CityAlpha",
        fields: {
            CityAlpha: {
                type: "string",
                validation: {
                    required: { message: "city alpha code is required" },
                    cityAlphacheckLength: function (input) {
                        input.attr("data-cityAlphacheckLength-msg", "a city alpha code must be 3 characters");
                        var ret = true;
                        if (input.is("[name=CityAlpha]")) {
                            ret = input.val().length == 3;
                        }
                        return ret;
                    }
                }
            },

            CityNumeric: {
                type: "string",
                validation: {
                    required: { message: "city numeric code code is required" },
                    cityNumericCheckLength: function (input) {
                        input.attr("data-cityNumericCheckLength-msg", "a city numeric code must be 4 characters");
                        var ret = true;
                        if (input.is("[name=CityNumeric]")) {
                            ret = input.val().length == 4;
                        }
                        return ret;
                    },
                    cityNumericIsNumeric: function (input) {
                        input.attr("data-cityNumericIsNumeric-msg", "a city numeric code must be numeric");
                        var ret = true;
                        if (input.is("[name=CityNumeric]")) {
                            ret = !isNaN(input.val());
                        }
                        return ret;
                    }
                }
            },

            Description: { type: "string",
                validation: {
                    required: false,
                    descriptionCheckLength: function (input) {
                        input.attr("data-descriptionCheckLength-msg", "a description cannot be longer than 80 characters");
                        var ret = true;
                        if (input.is("[name=Description]")) {
                            ret = input.val().length <= 80;
                        }
                        return ret;
                    }
                }
            },
           
            NextFlightEnabled: { type: "boolean" }
        }
    };

Back to Top