pierdeux
pierdeux

Reputation: 479

dojo: inheritance with default value - the mixin doesn't happen

I wish to declare a new dojo class inheriting from an existing dojo class, but with my own choice of default values for the class's properties. (The user can still override those values.)

I am declaring my own version of the dijit.form.FilteringSelect such that:

Here's what I did, without success:

dojo.provide("my.FilteringSelect");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
   "my.FilteringSelect",
   [
      dijit.form.FilteringSelect,  /* base superclass */
      { hasDownArrow:false, storeUrl:"/" }  /* mixin */
   ],
   {
      constructor: function(params, srcNodeRef){
         console.debug("Constructing my.FilteringSelect with storeUrl "
                        + this.storeUrl);
         this.store = new dojox.data.QueryReadStore({url:this.storeUrl});
      }
   }
);

Say, I try to generate declaratively in the HTML such a version of my.FilteringSelect:

<input type="text" id="birthplace" name="birthplace"
       promptMessage="Start typing, and choose among the suggestions"
       storeUrl="/query/regions"
       dojoType="my.FilteringSelect" />

This will indeed create a FilteringSelect with the desired promptMessage (which means that the superclass is properly getting the params), but hasDownArrow is true (contrary to my default mixin) and the store is null (and the Firebug console reports that storeUrl is "undefined").

What am I doing wrong?

Upvotes: 1

Views: 1539

Answers (1)

pierdeux
pierdeux

Reputation: 479

Oops! I really had things on their head. I found the right way around. The following works:

dojo.provide("my.FilteringSelect");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
   "my.FilteringSelect",
   dijit.form.FilteringSelect,
   {
      hasDownArrow : false,
      storeUrl : "/",
      constructor: function(params, srcNodeRef){
         dojo.mixin(this, params);
         console.debug("Constructing my.FilteringSelect with storeUrl "
                        + this.storeUrl);
         this.store = new dojox.data.QueryReadStore({url:this.storeUrl});
      }
   }
);

Upvotes: 1

Related Questions