CodeSeven / toastr

Simple javascript toast notifications
http://www.toastrjs.com
MIT License
11.99k stars 2.04k forks source link

Does Anyone know how to return values from onshow: function(){} #569

Open MichaelEugeneYuen opened 6 years ago

MichaelEugeneYuen commented 6 years ago

I am trying to create a custom toastrPrompt() function and get the return value(s)

<button type="button" class="btn btn-danger btn-delete">Delete</button>

$('.btn-delete').click( function(){
  var result = toastrPrompt();
  console.log(result);
})

function toastrPrompt() {
    toastr.options = {
                      progressBar: true,
                      showMethod: 'slideDown',
                      timeOut: 0,
                      tapToDismiss: false,
                      extendedTimeOut: 0,
                  };
  toastr.success('<br><br><button type="button" id="delete" class="btn btn-danger">Yes</button> <button type="button" id="close" class="btn btn-default">Cancel</button>',
  'delete item?', {
    closeButton: false,
    allowHtml: true,
    onShown: function () {
      $("#delete").click(function(){
        $(this).closest('.toast').fadeOut();
        return 'true';
      });
      $("#close").click(function(){
        $(this).closest('.toast').fadeOut();
        return 'false';
      });
    }
  });
}

jsfiddle

paddotk commented 6 years ago

This doesn't seem like a Toastr issue really, more of a general javascript issue. Perhaps it's best to post this question on StackOverflow..