Bootbox不显示连续加载的消息

时间:2016-11-23 06:46:43

标签: jquery bootbox

我正在使用bootbox对话框加载表单。表格定义如下:

<form id="classdefForm" method="POST" style="display:none">
    <div class="row">
        <div class="col-md-12 padfeedbackicon">
            <div class="form-group">
                <label class="control-label" for="cdcourseid">Course ID</label>
                <div class="input-group">
                    <input type="text" name="cdcourseid" id="cdcourseid" class="form-control dataaccess" placeholder="Course ID" required="" />
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-default" id="getClassCourseID"><span class="fa fa-bars"></span></button>
                    </span>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group padfeedbackicon">
                <label class="control-label" for="cdintake">Class Intake</label>
                <div class="input-group">
                    <input class="form-control date-picker" name="cdintake" id="cdintake" type="text" placeholder="Class Intake" data-date-format="yyyy-mm-dd" />
                    <span class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </span>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                <label class="control-label" for="cdstudymode">Study Mode</label>
                <select id="cdstudymode" name="cdstudymode" style="width:100%">
                    <option value="J">Module I</option>
                    <option value="S">Module II</option>
                </select>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                <label class="control-label" for="cdattendancemode">Attendance Mode</label>
                <select id="cdattendancemode" name="cdattendancemode" style="width:100%">
                    <option value="FT">Full Time</option>
                    <option value="PT">Part Time</option>
                    <option value="EV">Evening</option>
                    <option value="WE">Weekend</option>
                </select>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                <button type="submit" class="btn btn-default" id="saveclassdef"><i class="fa fa-save fa-lg" /> Create Class</button>
                <button type="reset" class="btn btn-default"><span class="fa fa-times-circle-o fa-lg"></span> Cancel</button>
            </div>                                
        </div>
    </div>
</form>

然后将表单加载到bootbox对话框中,如下所示:

$("#getDefineClassCode").on("click",function(){
       // alert($("#classdefForm").length);
        var diag=bootbox
            .dialog({
                message: $('#classdefForm'),
                title: "Class Definition",
                className: "modal-blue",
                show: false
            })
            .on('shown.bs.modal', function(e) {
                if(e.target===this)
                {
                    $('#classdefForm')
                        .show()                             /* Show the form */
                        .formValidation('resetForm', true); /* Reset form */
                }                
            })
            .on('hide.bs.modal', function(e) {
                if(e.target===this)
                {
                    $('#classdefForm').hide().appendTo('body');
                }
                //alert("")
            })
            .modal('show');

        //once the course id in the diag dialogue is clicked..
        diag.find("#getClassCourseID").on("click",function(){
        targetField=diag.find("#cdcourseid");
        GenericDialogue("courses","Courses");            
        })
        //setting the date picker for the cdintake
        diag.find(".date-picker").datepicker({autoclose:true}).on("changeDate",function(){
            $('#classdefForm').formValidation('revalidateField', 'cdintake');
        });

    });

在该对话框中,我加载了另一个引导程序对话框,该对话框在已显示的对话框中返回cdcourseid中的值。这很好。现在在将整个表单填入bootbox后,单击提交按钮,使用formValidation对其进行验证,对话框将关闭,如下所示:

$("#classdefForm").formValidation({
    framework: 'bootstrap',
    icon: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        cdcourseid: {
            validators: {
                notEmpty: {
                    message: 'Class course id is required'
                }
            }
        },
        cdintake: {
            validators: {
                notEmpty: {
                    message: 'Class intake is required'
                }
            }
        },
        cdstudymode: {
            validators: {
                notEmpty: {
                    message: 'Class study mode is required'
                }
            }
        },
        cdattendancemode: {
            validators: {
                notEmpty: {
                    message: 'Class attendance mode is required'
                }
            }
        }
    }
})
 .on("success.form.fv", function(e){
    e.preventDefault();
    //perform some operations here then hide the form
    // Hide the modal containing the form
    $form.parents('.bootbox').modal('hide');
});

之后我刷新了启动bootbox对话框的页面。 问题是,当我再次点击按钮时,booxbox对话框显示没有classdefForm我做错了什么? 希望我明白。谢谢!

1 个答案:

答案 0 :(得分:1)

$(document).ready(function() {
    // This WILL work because we are listening on the 'document', 
    // for a click on an element with an ID of #test-element
    $(document).on("click","#test-element",function() {
        alert("click bound to document listening for #test-element");
    });

    // This will NOT work because there is no '#test-element' ... yet
    $("#test-element").on("click",function() {
        alert("click bound directly to #test-element");
    });

    // Create the dynamic element '#test-element'
    $('body').append('<div id="test-element">Click mee</div>');
});