Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between dojoAttachpoint and id

Tags:

dojo

<div dojoType="dojo.Dialog" id="alarmCatDialog" bgColor="#FFFFFF" bgOpacity="0.4" toggle="standard">
<div class='dijitInline'>
       <input type='input' class='dateWidgetInput' dojoAttachPoint='numberOfDateNode' selected="true">
</div>

how to show this dialog I tried dijit.byId('alarmCatDialog').show();

The above code is a template and I called dijit.byId('alarmCatDialog').show() from the .js file .

dojo.attr(this.numberOfDateNode) this code works and I got the data .but if I change dojoattachpoint to id then I try dijit.byId('numberOfDateNode') will not work;

like image 799
eagerToLearn Avatar asked Jan 17 '23 09:01

eagerToLearn


1 Answers

Your numberOfDateNode is a plain DOM node, not a widget/dijit, i.e. javascript object extending dijit/_Widget, which is the reason you cannot get a reference to it via dijit.byId("numberOfDateNode"). Use dojo.byId("numberOfDateNode") instead and you are all set.

dojoAttachPoint or its HTML5 valid version data-dojo-attach-point is being used inside a dijit template to attach a reference to DOM node or child dijit to dijit javascript object, which is the reason dijit.byId('alarmCatDialog').numberOfDateNode has a reference to your <input type='input' class='dateWidgetInput' .../>.

The main reason to use data-dojo-attach-point is that:

  • you can create multiple instances of dijit and therefore your template cannot identify nodes/dijits by IDs as you will have multiple nodes/dijits with the same ID
  • it's an elegant declarative way, so your code won't be full of dijit.byId/dojo.byId.
like image 108
phusick Avatar answered Mar 21 '23 08:03

phusick