tags:

views:

476

answers:

2

I am trying to use the combobox provided by Dijit inside of a custom-made widget. I have been using Dojo's tutorial on comboboxes to guide me.

When I implement a stand-alone webpage similar to their tutorial examples, everything worked fine; but when I ported the code into my custom-made widget, it just renders the combobox as a plain HTML text box.

Here's what my custom widget's template looks like:

<div class='customWidget'>
    ...

    <div dojoAttachPoint="mainDiv" class="mainDiv">
        <div dojoType="dojo.data.ItemFileReadStore" jsId="stateStore" url="states.txt"></div>

        <input dojoType="dijit.form.ComboBox"
               store="stateStore"
               value="California"
               searchAttr="name"
               name="state2" />

        <button dojoAttachEvent="onclick:chooseState">OK</button>
    </div>

    ...
</div>

In the widget code, I require the combobox and read store:

dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");

I also tried putting these includes in a <script/> within the custom widget (similar to the way they do it in the tutorial), but it didn't work (in fact, it appears as if the script tag wasn't even evaluated, since I couldn't reference a function I declared inside of it!)

A: 

Have you tried adding:

<script type="text/javascript">
    dojo.require("dojo.parser");
    dojo.addOnLoad(function(){
        dojo.parser.parse();
    });
</script>

(from Dojocampus) to ensure Dojo is parsing the page? Are there any errors in your Javascript console? Is the page rendering any normal Dojo widgets?

Richy C.
I tried adding that code, but no dice. The main page that uses my custom widget executes a parse on load, so I'm guessing that should be a non-issue. There are no errors in my Javascript console. All Dojo widgets in the page are rendering fine, but I do not have any other Dojo widgets in my custom widget. Also, my custom widget is used inside of a dialog...not sure if that affects things.
+1  A: 

Do you have widgetsInTemplate in your widget declaration?

  dojo.declare('my.widget.Cool',[ dijit._Widget, dijit._Templated ], {

      widgetsInTemplate: true,

      // rest of widget JS here

   });

Here's an article about including other widgets in your template.

seth
That fixed it, thanks!
You are welcome. I make that mistake all the time. Glad it worked.
seth