1

I m creating a Dialog box in my javascript using Alertify library,

alertify.myAlert || alertify.dialog('myAlert',function factory(){
                return {
                    main:function(content){
                        this.setContent(content); 
                    },
                    setup:function(){
                        return {
                            options:{
                                modal:false,
                                basic:true,
                                maximizable:false,
                                resizable:false,
                                padding:false,
                                visible:false
                            }
                        };
                        },
                         hooks: {
                           onshow: function() {
                             this.elements.dialog.style.height = '50%';
                             this.elements.dialog.style.width = '15%';
                           }
                         }
                    };
            });

And, invoking it using below code..

alertify.myAlert("my html content");

Once it is launched, how can I close it ? I tried diff combinations like alertify.myAlert.close(), alertify.myAlert.hide() but nothing worked..

alex
  • 147
  • 1
  • 4
  • 17
  • 1
    use the parameter-less constructor to grab the dialog reference and then close() it `alertify.myAlert().close()` – MK. Dec 03 '15 at 13:02

3 Answers3

2

try this :-

alertify.alert().destroy(); 
Nero
  • 265
  • 1
  • 3
  • 12
  • it will delete the associted DOM and reset all settings to its initial state :) – Nero Dec 03 '15 at 05:44
  • destroy() & close() methods worked. But my dialog box, which shows a HTML form, didn't retain its previous entered form values when closed using these methods. Just wondering if there is any method to just HIDE the Dialog instead of destroying so that I don't need to enter all Form fields everytime I open the dialog. – alex Dec 03 '15 at 05:48
  • u can try using Closable: true in options. – Nero Dec 03 '15 at 05:58
  • close should not delete the associted DOM. – Nero Dec 03 '15 at 06:00
  • @Alekhya Use close() then show() to reopen the dialog without updating it's contents – MK. Dec 03 '15 at 12:46
1

@Nero, @MK : Thank you. close() and then show() did the job. They retain the state of dialog.

2 more questions,

  1. Can we refer an external HTML file inside alertify.dialog() implementation. Currently am using below code, which takes the html code and builds dialog content.

    alertify.myAlert('MY HTML Content');
    

    It looks dirty to have all html code in here. Do we have any option to specify path to html file?

  2. How to set the visibility of Dialog to false intially. I tried setting visibility:hidden, show:false, hide:true etc in options but didn work.

alex
  • 147
  • 1
  • 4
  • 17
  • It's better to move these questions to a separate post rather than having them inside of this answer! – MK. Dec 04 '15 at 12:21
0

you can use the same class by applying the remove

$('.alertify').remove();