javascriptjqueryjquery-maskalertifyjs

how to applique a mask on an Alertify.js prompt


Is there a way to applique a mask on a Alertify.js prompt ?

I need to add on a jquery maska like this :

$('document').ready(function(){
  $('.car_number').mask('(SSS-0000');
  });

On an alertify.js prompt like this :

alertify.prompt( 'test', 'Insert a car number', '', function(evt, value) {
               if(value) {
                   getVal(value);
                   }
                }
               , function() {})
}

to get an output like :

PCT-5077

Any help is welcome.


Solution

  • As long as you have acces to the DOM, you can do what ever you want:

    function show(){
      var prompt = alertify.prompt();
      prompt.set({
       'onshow': function(){
        var input = this.elements.content.querySelector('input');
        //customize the input as you please
        $(input).mask();
        },
        'onclose':function(){
          var input = this.elements.content.querySelector('input')
          //clear the customization as this is a singleton.
          //$(input) 
        }
      })
      .show();
    }
    

    But remember, the default AlertifyJS prompt is a singleton, so its better to clear the customization on close.