Bootbox确认立即执行回调而不单击按钮

时间:2015-05-13 12:44:29

标签: javascript jquery

我正在显示一个启动箱确认对话框。我想要的是当我点击" Ok"按钮它将触发我的回调功能。但是,在显示对话框时,立即执行回调函数。这是我的代码:

var update_violator = function update_violator(){
        var update_message = "";

        var callback_func = new function(){

                console.log('Executed agad!');
                //selected violator is assigned by referrence. Any changes made to this object automatically reflected in violators array.
                selected_violator.alias = $('#alias_v').val();
                selected_violator.first_name = $('#first_name_v').val();
                selected_violator.last_name = $('#last_name_v').val();
                selected_violator.middle_name = $('#middle_name_v').val();
                selected_violator.birth_date = $("input[name='birthdate_v']").val();
                selected_violator.gender = $("input[name='gender_v']:checked").val();
                selected_violator.educational_attainment = $('#educational_attainment_v').val();
                selected_violator.weight = $('#weight_v').val();
                selected_violator.height = $('#height_v').val();
                selected_violator.eyes_color = $('#eyes_color_v').val();
                selected_violator.hair_color = $('#hair_color_v').val();
                selected_violator.identifying_marks = $('#ident_marks_v').val();
                selected_violator.nationality = $('#nationality_v').val();
                selected_violator.mother_name = $('#mother_name_v').val();
                selected_violator.father_name = $('#father_name_v').val();
                selected_violator.father_name = $('#father_name_v').val();
                selected_violator.contact_person = $('#contact_person_v').val();
                selected_violator.contact_info = $('#contact_info_v').val();
                selected_violator.relationship = $('#relationship_v').val();
                selected_violator.street_name = $('#street_name_v').val();
                selected_violator.barangay_name = $('#barangay_name_v').val();
                selected_violator.city_name = $('#city_name_v').val();

                if(selected_violator.is_existing == true){
                    update_message="Violator successfully updated!\n This violator has a previous record in the database, in order to reflect the changes\n" +
                    " you've made you need to save the case report accordingly."
                }else{
                    update_message = "Violator successfully updated!"
                }

                bootbox.alert({ 
                    message: update_message,
                    title: "Message",
                    callback: function(){
                        $('#viewViolatorModal').modal('hide');
                        //console.log("Here: " + violators[0].alias);   
                    }           
                }); 

                update_violator_photos();               
        }
        Main.Mod.show_bootbox_confirm('Are you sure you want to update this violator?', 'Message', callback_func);  
    }

我的show_bootbox_confirm():

var show_bootbox_confirm = function show_bootbox_confirm(message, title, callback_func){
        bootbox.dialog({
            message: message,
            title: title,
            buttons: {
                success: {
                      label: "Ok",
                      className: "btn-success",
                      callback: callback_func,
                    },
                danger: {
                      label: "Cancel",
                      className: "btn-danger",
                      callback: function() {

                    }
                },
            }
        })  
    };

非常感谢您的回复!

感谢。

0 个答案:

没有答案