alertifyjs , How to specify actions for auxiliary buttons in AlertifyJS?


How to specify actions for auxiliary buttons in AlertifyJS?

Question:

Tag: alertifyjs

AlertifyJS has a place to put auxiliary buttons.

I would like for two things to happen when my auxiliary button is clicked

  1. The dialog should not close
  2. Some function should be run

How do I do these two things?

I can get the notification to show up by passing it as the third parameter, but the dialog disappears. Also, this wouldn't work if I had multiple auxiliary buttons and different functions for each.

Below is my javascript, and here is a JSFiddle.



    // Run this function when the auxiliary button is clicked
    // And do not close the dialog
    var helpInfo = function () {
        alertify.notify("help help help");
    };

    var custom = function () {
        if (!alertify.helper) {
            alertify.dialog('helper', function factory() {
                return {
                    setup: function () {
                        return {
                            buttons: [{
                                text: 'Help',
                                scope: 'auxiliary'
                            }],
                            options: {
                                modal: false
                            }
                        };
                    }
                };
            }, false, 'alert');
        }
        alertify.helper('Do you need help?', "hello world", helpInfo);
    };

    custom();


Answer:

AlertifyJS callbacks will be passed a special closeEvent object. To keep the dialog open, your callback should set the cancel property to true or simply return false.

var helpInfo = function (closeEvent) {    
   alertify.notify("help help help");    
   closeEvent.cancel = true;
  //or
  //return false;
};

See Updated Fiddle


Related:


How to specify actions for auxiliary buttons in AlertifyJS?


alertifyjs
AlertifyJS has a place to put auxiliary buttons. I would like for two things to happen when my auxiliary button is clicked The dialog should not close Some function should be run How do I do these two things? I can get the notification to show up by passing it...

Alertify dialog disappeared before confirming


javascript,alertifyjs
I was just writing some code and I met a problem like this: alertify.dialog("confirm").set( { 'labels': { ok: 'Personal', cancel: 'Share' }, 'message': 'Select target:', 'onok': function() { alertify.confirm($("#dir_select_user").get(0), function() { var i = $("#dir_select_user .dir_selector").val(); t.find(".move_des").val(i); t.find(".move_verify").val("1"); t.submit(); }).set('labels', { ok: alertify.defaults.glossary.ok, cancel: alertify.defaults.glossary.cancel }); }, 'oncancel': function() {...