JQuery Modal Reusable Dialog?

I have been using jquery to enable and disable for the past 6 months.

I have a form where I want to replace 20 different javascript warnings (""); using jQuery Modal dialog boxes.

I don't want to create a separate div div for every other post.

Is there a way with basic jquery-ui to create a reusable modal dialog where I can pass the post title and post body?

Let me know if you have any ideas?

Derek

0


a source to share


5 answers


There are many plugins you can find for jQuery for dialog boxes.

I've used the facebox plugin in the past.



Basic usage can be simple:

jQuery.facebox('something cool')

      

+3


a source


Yes, you can create a reusable dialog and you can pass the message dynamically.

  • Create dialog class

    function OkDialog() {
    
       this.showMessage = function(message) {
    
        var $dialog = $('<div></div>')
    
          .html(message)
    
          .dialog({
    
             modal: true,
    
             closeOnEscape: true,
    
             buttons: {
    
                Ok: function() {
    
                   $(this).dialog("close");
    
              }
    
            }
    
       });
    
          $dialog.dialog("open");
    
       }
    
    }
    
          

  • Create a global object in one of the shared files (jsp).

    OK_DIALOG = new OkDialog();
    
          

  • Call this function with the desired message.

    OK_DIALOG.showMessage("You don't have more than a single penny.");
    
          



Work is done!

+7


a source


I highly recommend Impromptu . It is well documented, has good examples and is mostly a javascript replacement for Alert and Input, however it is very extensible and has tons of options and extra features.

+2


a source


I would recommend the jQuery Growl plugin. http://plugins.jquery.com/project/Growl

The advantage of using Growl is that it has some really good built-in features, in particular the added ability to have an auto-delete feature.

It is not modal-modal.

What I mean is that the user is not required to interact with it before they can return to interacting with the site, thus maintaining the website's workflow.

+1


a source


I've used Facebox quite a bit before, but I'm ditching it in favor of a dialog that is part of the jQuery UI collection:

http://docs.jquery.com/UI/Dialog

You mentioned core jquery-ui, doesn't that do the trick?

+1


a source







All Articles