0

Is there a way to obtain the underlying object from dom element.

For instance.

  • I have a base class which renders some buttons using goog.ui.CustomButton.
  • In the child class I want to get underlying goog.ui.CustomButton object through the generated dom element.

Is it possible or do I need to cache the underlying objects:

    mylib.Base = function() {
    };

    mylib.Base.prototype.renderButtons = function(buttonTypes) {
      for(var i in buttonTypes) {
        var button = new goog.ui.CustomButton();
        var buttonContainer = goog.dom.getElement('button-container_' + buttonTypes[i]);
        button.render(buttonContainer);
      }
    };


    mylib.Child = function() {
      mylib.Base.base(this, 'constructor');
    };
    goog.inherits(mylib.Child, mylib.Base);


    mylib.Super.prototype.someTask = function() {
      this.renderButtons(['save_button','cancel_button']);
      var saveButtonHolder = goog.dom.getElement('button-container_' + 'save_button');
      var saveButtonElement = saveButtonHolder.childern[0]; // Not production code

      // Now Is it possible to get the goog.ui.CustomButton object through the
      // saveButtonElement ?
    };
Anupam Saini
  • 2,431
  • 2
  • 23
  • 30
  • this is more of a design issue - you can always keep a Object reference this.buttonList_['mybuttonname'] = new CustomButton() and getMyButtonList (){ return this.buttonList_; } in parent class – aked Jul 10 '14 at 17:32
  • The base class is not maintained by me and I want to avoid any modifications to it. Will it be possible to get a reference? – Anupam Saini Jul 11 '14 at 02:13
  • 2
    you can not , But since this is Javascript - there is always a HACK. what you can do is you can OVERRIDE the prototype method mylib.Base.prototype.renderButtons in your file. and add your feature to it . This is something i have done here - https://github.com/dekajp/google-closure-grid/blob/master/src/pear/ui/editor/dateeditor.js#L94 when you compare the method with original method (goog.ui.InputDatePicker.prototype.setInputValue) in Closure Library you can see my change – aked Jul 11 '14 at 03:18
  • @dekdev I will be better off submitting a patch on the base file which caches the button objects. Thanks again for taking out the time to answer my question. – Anupam Saini Jul 14 '14 at 08:15

0 Answers0