-2

I want to know the difference between in html and javascript.

  1. dijit.byId("link_id").value = linkData.link_id;
  2. dijit.byId("link_id").set("value",linkData.link_id);

because, when I used the first option, it did not set the value in the linkid textbox, but the second option did that. So just wanted to know what is happening in both situations.

Antony
  • 14,900
  • 10
  • 46
  • 74
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
  • This question is not about HTML attributes. No reason to have it closed as a duplicate. Proof (this is part of the source code that handles the setters): https://github.com/dojo/dijit/blob/master/_WidgetBase.js#L785 – g00glen00b May 14 '14 at 11:45

1 Answers1

0

The difference is that using the first method, you're directly setting a property of the widget object, for example, setting the value.

In the second example however, you're using the setter provided by dijit/_WidgetBase, which in turn calls a _set function, for the value property it would be _setValueAttr(). Widgets can extend these setters with custom functionality that will happen when using that setter. For example it can take the necessary steps to display the value as well.

If we, for example pick a dijit/form/Select widget and look at the code of _setValueAttr(), we notice that it calls some extra functions like:

domAttr.set(this.valueNode, "value", this.get("value"));
this._refreshState();   // to update this.state

This functionality is only called when using dijit.byId("link_id").set("value", "myValue");, and that's the reason why your value is only displayed in this case. When you're directly setting the property, you're "short-circuiting" this functionality.

TL;DR: Always use the setter function when using Dojo widgets.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133