Total Pageviews

2018/05/08

[Bootbox] How to set button focus in bootbox dialog

Problem
I am using Bootbox.js to create a custom dialog

The default behavior is focusing on the second button, i.e. EXCEL, how to I change its focus to the first button.

The code snippet is as bellows:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  $scope.doExport = function() {
     bootbox.dialog({
     message: "請選擇要匯出 JSON 或 Excel",
         title: '匯出',
         buttons: {
            json: {
                label: 'JSON',
                callback: function() {
                    $scope.exportJson();
                }
            },
            excel: {
                label: 'Excel',
                callback: function() {
                    $scope.exportExcel();
                }
            }
         }
     });
  };


How-To
You can simply add btn-primay class to the first button, the code snippet is as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
   $scope.doExport = function() {
     bootbox.dialog({
         message: "請選擇要匯出 JSON 或 Excel",
         title: '匯出',
         buttons: {
             json: {
                 label: 'JSON',
                 className: 'btn-primary',
                 callback: function() {
                     $scope.exportJson();
                 }
             },
             excel: {
                 label: 'Excel',
                 callback: function() {
                     $scope.exportExcel();
                 }
             }
         }
     });
   };


Here has the updated dialog:



No comments: