JQuery page level validator

So, I already wrote a special jQuery validation method. And it is tied to 1 or more individual drop-down lists . (I'm in asp.net, by the way)

jQuery.validator.addMethod("dropdownBoxHasItemSelected", function (value, select, arg) {
    var returnValue = false;
    var selectedIndex = $(select).prop("selectedIndex");
    if (selectedIndex != 0) {
        returnValue = true;
    }
    return returnValue;
}, "Please select a item.");

So this is not my question.

I have a check that needs to be done at the page level. Or maybe at the "GridView" level is the best way to express this.

Here's the scenario: (I use pre-made data to simplify the explanation, aka, I really don't have Toys and Products).

I have a grid.

Column A of the gridview is of no consequence of this, but it exists.
Column B of the gridview has a DropDownList for "FavoriteToy". 
Column C of the gridview has a DropDownList for "FavoriteFood".

So the rules go something like this.

For each row in gridview:

You must pick a FavoriteToy or a FavoriteFood for each row.
You can pick a FavoriteToy OR a FavoriteFood, but not both on the same row.
If you pick a FavoriteToy of "TeddyBear" in RowX, none of the other rows can have TeddyBear chosen. (Aka, each row must have a distinct FavoriteToy chosen)
If you pick a FavoriteFood of "AppleButter" in RowX, none of the other rows can have AppleButter chosen. (Aka, each row must have a distinct FavoriteFood chosen)

If desired, you can add new new rows to the gridview. There is also a “delete” button, just in case the user has exhausted all combinations of FavoriteToy and FavoriteFood.

( jQuery ).

, " ", jQuery.validator.addMethod.

, asp: Label ( "" = "" ), .

, , "" .

- ?

=============================================== =====================

:

asp: net:

<asp:HiddenField ID="hidGridViewValidatorPlaceHolder" runat="server" />

jQuery.validator.addMethod("gridViewValiatorMethod", function (value, select, arg) {
    var returnValue = true;
    var errorMsg = SuperValidationWrapper();
    if (errorMsg != "") {
        alert(errorMsg);
        returnValue = false;
    }
    return returnValue;
}, "Please address the issues in the gridview.");

SuperValidationWrapper() . , - . , , .

, ", gridview". , - .

.

+5

All Articles