Search code examples
javascriptalertifyjs

Alertifyjs validation on prompt


I'm using alertifyjs that's great but I have a small issue I wish to solve, maybe with your help.

Using the Prompt Component I would like to force the user to write a "reason" in the input field and to be honest I don't know how to do that...

Actually my code is like that:

  alertify.prompt(
        'Warning!',
    'Are you sure you wish to CANCEL the order?',
    'Enter reason please...',
    function (e, reason) {
      // my code on confirm...
    },
    function () {
        return;
    }
  );

I hope you can help.


Solution

  • The documentation show the following:

    alertify.prompt(
        'Warning!',
        'Are you sure you wish to CANCEL the order?',
        'Enter reason please...',
        function (e, reason) {
           if( reason == '' ) { 
               e.cancel = true;
           }
          // my code on confirm...
        },
        function () {
            return;
        }
      );
    

    http://alertifyjs.com/prompt/onok.html To prevent the dialog from closing, either set closeEvent.cancel = true or make your callback return false .