Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:01:23+00:00 2026-05-26T03:01:23+00:00

When using jQueryUi widgets (dialog, datepicker etc) I always wonder if there would be

  • 0

When using jQueryUi widgets (dialog, datepicker etc) I always wonder if there would be better to wrap the widgets in some kind of wrapper class. Here is one way to do this, but I’m not sure if this is good practice.

Please comment

CODE

Small plugin for $ that wraps ‘dialog’.

//Widget Wrapper plugin POC.
//Should be extended to support all Methods on all Widgets in jQueryUI   
(function ($) {
    $.fn.ww = function (uiWidgetName, options) {
    if (this.length == 1) {
        return new wrappers[uiWidgetName](this[0], options);
    }
}


var wrappers= {};

wrappers.dialog = function (element, options) {
    var theWidget = $(element);
    theWidget.dialog(options);

    this.open = function () {
        theWidget.dialog('open');
    }
    this.close = function () {
        theWidget.dialog('close');
    }
  }

} (jQuery))

This could be used like this

var a = $("#WrapperTest").ww('dialog',{ autoOpen: false });            
a.open();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:01:23+00:00Added an answer on May 26, 2026 at 3:01 am

    Well, actually, the functions added to the $.fn namespace by jQuery UI ($.fn.dialog() in your case) are already wrappers around each widget’s methods.

    It looks like you want to implement some kind of “reverse-wrapper” around the existing dialog() wrapper in order to be able to access the widget’s methods directly. Adding another layer of overhead is not necessary, as you only have to invoke the widget’s constructor directly, specifying the widget options and the target element:

    var dialogWidget = new $.ui.dialog({
        autoOpen: false
    }, $("#WrapperTest")[0]);
    

    Then you can do things like:

    dialogWidget.open();
    dialogWidget.close();
    dialogWidget.option("autoOpen", !dialogWidget.option("autoOpen"));
    // and so on.
    

    If you have created a dialog the “usual” way (through $.fn.dialog()) and you want to to obtain a reference to its widget instance further down the line, you can fetch it from the element’s data using the widget’s name as the key:

    $("#WrapperTest").dialog({
        autoOpen: false
    });
    
    var dialogWidget = $("#WrapperTest").data("dialog");
    dialogWidget.open();
    

    You can test the code above in this fiddle.

    Update: From jQuery UI 1.9 onwards, the data() key becomes the widget’s fully qualified name, with dots replaced by dashes. Therefore, the code above becomes:

    var dialogWidget = $("#WrapperTest").data("ui-dialog");
    dialogWidget.open();
    

    Using the unqualified name is still supported in 1.9 but is deprecated, and support will be dropped in 1.10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create popup using the jqueryui dialog. I am trying to
I am using the jquery datepicker ( http://jqueryui.com/demos/datepicker/ ). The datepicker on the demo
To give more information I am using the modular form here: http://jqueryui.com/demos/dialog/#modal-form `b(e.target).zIndex` is
I am using the JQUeryUI to present a Dialog Box to the end user
I am using the ui date picker widget here: http://jqueryui.com/demos/datepicker/ to populate this: <input
My Needs: I am using a jquery modal dialog. I have some buttons on
I created a theme using http://jqueryui.com/themeroller/ all of the ui-widgets are functioning properly with
I'm using jqueryUI's widget factory to extend jqUI's dialog widget. I've setup the simplest
I am using the jQueryUI dialog widget in a website I'm developing. Basically, the
I'm using JqueryUI for drag and drop on one of my pages and for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.