javascript - 当我关闭对话框时,jQuery 验证 ResetForm 错误

标签 javascript jquery jquery-ui-dialog

我正在使用 jQuery 验证:http://bassistance.de/jquery-plugins/jquery-plugin-validation/并且无法将验证消息重置为默认状态。 IE;没有突出显示。我想要实现的目标是,如果我关闭对话框窗口,那么验证器会将自身重置为就像窗口首次打开一样的状态。然而,当我通过单击 X 关闭对话框并重新打开时,错误消息仍然存在。我不确定 resetForm() 应该去哪里以及是否必须准备一个对话框(“关闭”)过程。

我只发布了我认为与问题相关的代码。

如果有人能指出我的错误,我将不胜感激。谢谢

else if (this.name === 'Administration') {
    $("#formShow").show();
    // admin clicked

    //$("#confirm_department").show().html("You have selected administration");
    $("#formImage .col_1 li").hide();
    var $dialog = $('#frmreport');
    $dialog.dialog({
        autoOpen: true,
        modal: true,
        title: 'Submit a ' + name + ' report',
        width: 500,
        height: 400,
        draggable: false,
        resizable: true,
        // buttons: {
        // Close: function() {
        // $( this ).dialog( "close" );
        // $("#frmreport").get(0).reset();
        // }
        // }
    });
    //$( '#frmreport' ).dialog( 'close' );
    //$("#frmreport").get(0).reset();

    //console.log(name);
    $('input[name=dept]').val(name);
    $(".subtitle").text("Submit " + name + " feedback report");
    //code   
}

编辑:根据您的评论更新了代码

else if(this.name === 'Administration') {

            $("#formShow").show();

           // admin clicked


             //$("#confirm_department").show().html("You have selected administration");
             $("#formImage .col_1 li").hide();
             var $dialog = $('#frmreport');
               $dialog.dialog({
               autoOpen: true,
               modal: true,
               title: 'Submit a ' +name+ ' report',
               width: 500,
               height: 400,
               draggable: false,
               resizable: true,
               Close: function(event, ui) {
               $("#frmreport").validate().resetForm();
               }
               // buttons: {
               // Close: function() {
               // $( this ).dialog( "close" );
        // $("#frmreport").get(0).reset();
               // }
               // }
               });
        //$( '#frmreport' ).dialog( 'close' );
                //$("#frmreport").get(0).reset();

                //console.log(name);

             $('input[name=dept]').val(name);
             $(".subtitle").text("Submit " + name + " feedback report");

          //code   
        }

最佳答案

在您的Close 函数中尝试一下:

 $dialog.dialog({
    close: function(event, ui) {
               $("#frmreport").validate().resetForm();
           }
 });

关于javascript - 当我关闭对话框时,jQuery 验证 ResetForm 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19731796/

相关文章:

javascript - "label.error"似乎总是出现在每个 Bootstrap 选项卡上

javascript - localStorage 在 IE9 和 Firefox 中不工作

javascript - 将 CSS 样式添加到 SVG

javascript - jQuery:获取某些元素的下一个实例

javascript - Velocity.js 绕中心轴旋转

jquery-ui - JQuery UI 对话框只能水平调整大小,不能垂直调整

jQuery UI 对话框 : how to add tabs to content area?

javascript - URL 中的数字逐渐增加 - JavaScript

optgroup 上的 jQuery 过滤器

javascript - jQuery UI CSS 使 Firefox 与 Chrome 中的对话框内容不同