views:

560

answers:

1

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:

  • the hasDownArrow property defaults to false (rather than the standard true) and
  • there's an extra possible property storeUrl which allows me to connect the FilteringSelect to the corresponding QueryReadStore.

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?

A: 

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});
      }
   }
);
pierdeux