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

Using grid validation in a form

0 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 02 Aug 2012, 03:45 PM
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" }
    }
};

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Brad
Top achievements
Rank 1
Share this question
or