Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Make customDialog method return an promise to the bootbox dialog instance #46

Open
betonetotbo opened this issue Oct 4, 2016 · 0 comments

Comments

@betonetotbo
Copy link

I changed the customDialog method to return a promise that resolves to the bootbox dialog instance.

This is very useful, for example, to plug an shown.bs.modal event and perform a custom focus.

The ngBootbox.js change (added a promise as return):

customDialog: function (options) {
var deferred = $q.defer();

if (options.templateUrl) {
  getTemplate(options.templateUrl)
    .then(function (template) {
      options.scope = options.scope || $rootScope;
      options.message = $compile(template)(options.scope);
      deferred.resolve($window.bootbox.dialog(options));
    }, function () { //Show default dialog if no template could be found
        deferred.resolve($window.bootbox.dialog(options));
    });
}
else {
    deferred.resolve($window.bootbox.dialog(options));
}

return deferred.promise;
},

This is an example, a dialog with an input and a table as the dialog body:

<script type="text/ng-template" id="my-template.html">
    <input placeholder="Enter your search" />
    <table>
         <tr ng-repeat=".....">
         </tr>
    </table>
</script> 

<script type="text/javascript">
    $ngBootbox.customDialog({
        title: 'Search dialog',
        template: 'my-template.html'
        buttons: {
            'ok': { label: 'OK', className: 'btn-primary' },
            'cancel': { label: 'Cancel', className: 'btn-default' }
        }
    }).then(function(dialog) {
        // on dialog SHOW...
        dialog.one("shown.bs.modal", function() {
          // ... focus on the first INPUT tag
          dialog.find("input:first").focus();
        });
    });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant