How can I disable/enable a button in a bootbox dialog box

时间:2015-06-30 19:27:10

标签: jquery knockout.js

How can disable/enable the Save button?

bootbox.dialog({
    message: [
    '<div class="title"'>,
    <h4>Title</h4>',
    </div>'].join(''),
    buttons: {
      label: 'Save',
      callback: function(){ // function code here  .....
      });

3 个答案:

答案 0 :(得分:2)

想出来:

$('.btn-save').prop("disabled", true);

其中btn-save是按钮的className。

答案 1 :(得分:0)

对于那些使用AngularJS的人,在这里如何在ng-model =“name”的文本输入中存在值时禁用/启用按钮:

var dialog = bootbox.dialog({
    title: title,
    message: '<input type="text" ng-model="name" />',
    buttons: {
        apply: {
            label: 'Apply',
            className: 'btn btn-primary apply-btn',
            callback: function() {
                // whatever
            }
        },
        cancel: {
            label: 'Cancel',
            className: 'btn btn-default',
        }
    }
});

dialog.bind('shown.bs.modal', function() {
    $applyBtn = $(this).find('.apply-btn');
    $applyBtn.attr('ng-disabled', '!name');
    $compile($applyBtn)($s);
});

答案 2 :(得分:0)

使用web调试器(在回调函数上停止)我找到了一个基于user2884789的aswer的解决方案:

$(this).find('button');

save className按钮将出现在列表中;例如:'button.btn.btn.btn-sm.btn-primary'

所以我在回调函数中禁用了保存按钮:

$(this).find('button.btn.btn.btn-sm.btn-primary').prop('disabled', true);

这对我有用。

相关问题