そのため、カスタム jQuery バリデーター メソッドは既に作成しています。また、1 つ以上の個別のドロップダウン リストに関連付けられています。(私はasp.netにいます、ところで)
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.");
だから、それは私の質問ではありません。
「ページレベル」で行う必要がある検証があります。または、「GridView」レベルで表現する方が良いかもしれません。
シナリオは次のとおりです(説明を簡単にするために作成したデータを使用しています。別名、おもちゃと食べ物は実際にはありません)
私はグリッドビューを持っています。
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".
したがって、ルールは次のようになります。
グリッドビューの各行について:
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)
必要に応じて、新しい行をグリッドビューに追加できます。ユーザーがすべての FavoriteToy と FavoriteFood の組み合わせを使い果たした場合に備えて、「削除」ボタンもあります。
これで、すべての検証ロジック (jQuery 構文を使用して値をチェックし、すべてをループ) を問題なく記述できました。
jQuery.validator.addMethod を使用して、「グリッド ビュー全体のバリデーター」を接続する方法についてのアドバイスを探しています。
asp:Label (クライアント側の type="text" の「入力」) に接続できるので、エラー メッセージがそこに表示されると思います。
または、クライアント側でグリッド ビューが「テーブル」としてレンダリングされる場合もあります。
一般的なアドバイスはありますか?
================================================== ==================
私がこれまでに入れたこと:
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() にはすべてのループループがあります。そして、問題があるという連結文字列を返します。私はそれが好きではありませんが、それが私がやったことです。
アラート ボックスに詳細が表示され、「グリッドビューの問題に対処してください」というテキストが表示されます。問題がある場合に表示されます。
改善点は大歓迎です。