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 6943029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:06:08+00:00 2026-05-27T13:06:08+00:00

I am using the Dojo JS framework 1.6 to declare and track custom classes.

  • 0

I am using the Dojo JS framework 1.6 to declare and track custom classes. I want to use these classes to create reusable functionality such as user edit dialogue box and so on..

The problem is however when using a method inside the class to create a dojo html type button for example. If that button then needs to call a method back within the class, it doesn’t know the instantiated variable to call..

How would i get stage2 to reference this instance of the class without hard coding the object name?

Example Class:

dojo.provide('edit.contacts');
dojo._hasResource["edit.contacts"] = true;

dojo.declare("edit.contacts", null,
{
   /*
   *     Init
   */
   init   : function(customer_id)
   {
      var out = ''
      +'<button dojoType="dijit.form.Button" onClick="stage2();" />Edit</button>'
      +'';

      // Create the dlg box
      var edit_contacts_dlg = new dijit.Dialog(
      {
         title    : 'New Diag',
         style    : 'width:550px; height:600px;background:#FFFFFF;',
         id       : 'edit_contacts_dlg',
         content  : out
      }).show();
   },

   /*
   *     Stage 2
   */
   stage2   :  function()
   {
      alert('halllo');
   }
}

Example Usage:

  • 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-27T13:06:09+00:00Added an answer on May 27, 2026 at 1:06 pm

    It’s a problem of scope. You will always face this kind of problem when mixing JS and HTML to create nodes or widgets. You need a reference to the instance of the button widget in the moment you’re calling init() method, which you don’t have because you used HTML and dojo.parser to create the button. Basically, you have three ways out:

    1. Create the button programmatically and give it the onClick either directly or via a dojo.connect. This is very flexible since you can literally pass any function, using any variables in scope, to the onclick.

      var out = new dijit.form.Button({
          label: 'Edit',
          onClick: dojo.hitch(this, 'stage2')
      });
      var edit_contacts_dlg = new dijit.Dialog({
          title    : 'New Diag',
          style    : 'width:550px; height:600px;background:#FFFFFF;',
          id       : 'edit_contacts_dlg_' + uniqueId,
          content  : out
      }).show();
      
    2. Generate unique id for each instance of edit.contants class and insert it into your html string. Then obtain the instance of the button via dijit.byId() and do the above mentioned connect:

      var out = '<button dojoType="dijit.form.Button" id="' + uniqueId + '">Edit</button>';
      var edit_contacts_dlg = new dijit.Dialog({
          title    : 'New Diag',
          style    : 'width:550px; height:600px;background:#FFFFFF;',
          id       : 'edit_contacts_dlg_' + uniqueId,
          content  : out
      }).show();
      var btn = dijit.byId(uniqueId);
      dojo.connect(btn, "onClick", this, "stage2");
      
    3. Create class based on dijit._Widget and dijit._Templated, i.e. widget, and use its data-dojo-attach-point feature to obtain button instance (see it in action at jsFiddle):

      dojo.require("dijit._Widget");
      dojo.require("dijit._Templated");
      dojo.require("dijit.Dialog");
      dojo.require("dijit.form.Button");
      
      dojo.ready(function() {
      
          dojo.declare("edit.ContactTemplate", [dijit._Widget, dijit._Templated], {
              templateString: '<div><button data-dojo-type="dijit.form.Button" data-dojo-attach-point="editBtn">Edit</button></div>',
              widgetsInTemplate: true    
          }) 
      
          dojo.declare("edit.contacts", null, {
      
              init: function(customerId) {
                  this.customerId = customerId;
      
                  var widget = new edit.ContactTemplate();
                  dojo.connect(widget.editBtn, "onClick", this, "stage2");
      
                  this.editContactDlg = new dijit.Dialog({
                      title    : "Dialog: " + customerId,
                      style    : "width:200px;height:80px;background:#FFFFFF;",
                      id       : "edit_contacts_dlg_" + customerId,
                      content  : widget
                  });
      
                  this.editContactDlg.show();
                  return this;
              },
      
              stage2:  function() {
                  alert(this.customerId);
              }
          });
      
          var c1 = new edit.contacts().init("customer #1");
          var c2 = new edit.contacts().init("customer #2");
      });
      

    This is useful when you need a reference to many widgets/nodes.

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

Sidebar

Related Questions

Using dojo.dnd, I want to allow a user to drag only one item at
I'm looking at using the Dojo Objective Harness (DOH) for testing some custom JavaScript
I'm trying to create a DOJO DataGrid populated using a dojo.data.ItemFileReadStore with very simple
I am using the following date timepicker of dojo framework on my jsp, i
I am using dojo datagrid to display my data. When the end user edit
I'm using Dojo framework to help me in my Javascript development with cross browsing
I found facebook style autocomplete using jQuery. But im using dojo framework for my
I am using Dojo 1.2 to implement some functionality on my customer's webpage. One
I'm using Dojo Drag and Drop. When a user adds an item to a
I am using Dojo and Zend Framework. I have a bunch of accordions on

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.