Alertifyjs validation on prompt Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Alertifyjs validation on prompt without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

Answer

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 .

We are here to answer your question about Alertifyjs validation on prompt - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji