2

I am using jQuery alertify prompt http://alertifyjs.com/prompt.html

Is there any way to make textbox mandatory by defining attributes directly?

Thanks

Jatin Dhoot
  • 4,294
  • 9
  • 39
  • 59

1 Answers1

1

You can get a reference to the input box using elements property:

alertify.prompt().set('onshow',function(){
   $(this.elements.content).find('.ajs-input').attr('required', true); 
});

But this will not prevent the dialog from closing when you press OK, to prevent that you need to check the value parameter and cancel the close event if it's empty:

alertify.prompt('Input required')
        .set('onok', function(e, value){
            if(!value) e.cancel = true; 
         });
MK.
  • 5,139
  • 1
  • 22
  • 36
  • Yeah, that can be done. I thought there should be some easy way to define mandatory param. Thanks for your efforts – Jatin Dhoot Sep 28 '15 at 08:44