Loading ...
Sorry, an error occurred while loading the content.

Re: cannot access dialog form property from subclass

Expand Messages
  • Michael Mogley
    Satyen, Thank you for that very helpful reply. I may not have been using this.form . I made that change and also the switch to initialize the superclass
    Message 1 of 3 , Feb 6, 2009
    • 0 Attachment
      Satyen,

      Thank you for that very helpful reply. I may not have been using
      'this.form'. I made that change and also the switch to initialize the
      superclass directly as you suggested, and it now works!

      Michael

      --- In ydn-javascript@yahoogroups.com, "Satyen Desai" <sdesai@...> wrote:
      >
      > Hey Michael,
      >
      > The snippet you provided seems to show your current solution (where
      you're retrieving the form from the DOM).
      >
      > Not sure how you were trying to access it previously, so can't
      really tell what was wrong (seems like you may not have been accessing
      it using "this"), but the following example seems to work OK, if you
      want to use it for reference:
      >
      > http://yuiblog.com/sandbox/yui/v260/examples/container/ExtendDialog.html
      >
      > Also, a couple of general observations on the extension code, which
      are unrelated but maybe worth noting.
      >
      > 1). It's probably better not to use
      "this.constructor.superclass.XXXXX".
      >
      > Use the static reference to the constructor function directly. e.g.:
      >
      > XMPS.StoreManager.Panel.ProfileDialog.superclass.XXXXX
      >
      > Although it'll work for instances of your class, as is, you'll find
      that if someone goes to extend ProfileDialog, they'll hit an infinite
      recursion when they go to chain any methods in which you use
      "this.constructor" to chain.
      >
      > For example the "this.constructor" in ProfileDialog's constructor
      will refer to their subclass constructor, instead of ProfileDialog as
      you're expecting it to - which will loop back round to call
      ProfileDialog, and so on.
      >
      > 2). You shouldn't need to use superclass.setHeader(), unless you
      specifically want to bypass your implementation of setHeader().
      >
      > Simply using this.setHeader() will look up the prototype chain for
      the implementation - whether it's ProfileDialog, Dialog or one of
      Dialog's superclasses which is providing it.
      >
      > If you were using "superclass" to access the form property as
      opposed to "this", this is probably what the problem was.
      >
      > Hope that helps,
      > Satyen
      >
      > ________________________________________
      > From: ydn-javascript@yahoogroups.com
      [mailto:ydn-javascript@yahoogroups.com] On Behalf Of Michael Mogley
      > Sent: Thursday, February 05, 2009 4:59 PM
      > To: ydn-javascript@yahoogroups.com
      > Subject: [ydn-javascript] cannot access dialog form property from
      subclass
      >
      > I've written a subclass of the Dialog widget. In that subclass, I'm
      > attempting to dynamically change the form action based on UI events.
      >
      > The issue I have is I'm not able to access the form property of the
      > Dialog superclass from within the subclass. I am forced to retrieve
      > the form element directly from the DOM. This, as I learned, does not
      > have the desired effect, since the Dialog uses an internal copy of the
      > form for submission.
      >
      > Am I missing something about how to correctly extend the Dialog class?
      >
      > My subclass code is below.
      >
      > Thanks for any help.
      >
      > Michael
      >
      > (function() {
      > //~ Private Members --------
      > var m_record;
      >
      > //~ Constructors -------
      > XMPS.StoreManager.Panel.ProfileDialog = function (name, config)
      > {
      > this.constructor.superclass.constructor.call(this, name, config);
      > };
      >
      > YAHOO.lang.extend(XMPS.StoreManager.Panel.ProfileDialog,
      > YAHOO.widget.Dialog);
      >
      > //~ Private Methods -------
      > var getForm = function()
      > {
      > return document.forms.profileForm;
      > }
      >
      > //~ Public Methods -------
      > XMPS.StoreManager.Panel.ProfileDialog.prototype.setMode = function(mode)
      > {
      > switch (mode)
      > {
      > case XMPS.UI.Mode.ADD:
      > this.constructor.superclass.setHeader.call(this, "Add new
      > profile");
      > getForm().action.value = "/proxy/profile/add";
      > break;
      >
      > case XMPS.UI.Mode.EDIT:
      > this.constructor.superclass.setHeader.call(this, "Edit profile");
      > getForm().action.value = "/proxy/profile/update";
      > break;
      > }
      > }
      > })();
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.