-2

私は自分の問題の良い解決策を見つけようとして立ち往生しています。日付の検証イベントでポップアップウィンドウを表示する方法を教えてもらえますか?検証にjQuery検証プラグイン1.6(jquery.validate.js)を使用しています。私のシナリオでは、ユーザーが日付を選択すると、その日付を検証し、無効な場合は適切なエラーメッセージを表示します。日付が無効な場合は、パスワードのポップアップウィンドウで無効な日付を有効にします。残念ながら、これに対する適切な解決策は見つかりませんでした。

これは私が持っているコードです:

$(document).ready(function () {
    ...
    $('#txtDate').rules("add", { required: true, restrictDate: true, messages: { required: "Please enter log date", restrictDate: "Check the selected date." } });
    ...
    $.validator.addMethod("restrictDate", function (value, element) { var activityDate = GetDate($('#txtDate').val(), formatOfDate); if (Date.parse(activityDate) > Date.parse(dt)) { return false; } else return true; }, "Date comparison error." );
    ...
    //Registering date picker
    $('#txtDate').datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true, constrainInput: true });

...
....

)};

4

2 に答える 2

0
if(!$('#dateId').valid()){
    $('#divId').html("Error message");
    $( "#divId" ).dialog();
}
于 2013-03-19T06:36:49.340 に答える
0

jQuery UIのダイアログ コンポーネントを見たことがありますか? 必要なメッセージを含む任意のモーダル ダイアログ (ポップアップ) を表示できます。

jQuery 検証プラグインを使用して、次のinvalidHandlerように検証を呼び出すときに使用します。

$(".selector").validate({
    invalidHandler: function(event, validator) {
        // If there are any errors in your form, control reaches this function
        // First check if your date field was the source of the error
        if(validator.element('#datefield')){
            // If it was, show the dialog box you want.
            $('#yourdiv').html("<div> Any html message/content you want here</div>");
            $('#yourdiv').dialog();
        }
    }
 })
于 2013-03-19T06:34:52.900 に答える