Set Value Dijit.Form.Textarea

I have a dijit dialog containing a form that I want to fill out automatically. I can display a dialog box with a form in it, but I was not able to set the value of the text area in the form. Here is the div where the html is located.

<div dojoType="dijit.Dialog" id="formDialog" title="Form Dialog" > <table> <tr> <td> <label for="desc"> Description: </label> </td> <td> <textarea id="desc" name="desc" dojoType="dijit.form.Textarea" style="width:200px;"></textarea> 

SAVE CLOSE

I can get this to display just fine by doing

var formDlg = dijit.byId ("formDialog"); formDlg.show ();

But the problem is that I am setting the value of a text field called "desc". I tried a few things, but I know what I need

 var test = dijit.byId("desc"); 

but if I set any property of the test, for example

  test.value = "foo"; test.textContent = "foo"; test.innerHTML = "foo"; test.srcNodeRef = "foo"; 

The value is never saved and displayed inside the text box. Is there any trick for this? Any help would be great. Thanks

+6
javascript dojo
source share
2 answers
 var test = dijit.byId("desc"); test.set("value", "foo"); 

.. should do the trick, I think. Most widgets in Dojo use the set (formerly attr ) method to set property values, rather than manipulating them directly as you tried to do. You can also set several properties in one pass by passing an object:

 var test = dijit.byId("desc"); test.set({"value": "foo", "name": "someName"}); 
+11
source share

For some reason, dijit.byId("txtAreaMytextarea").set("value", "somevalue") does not work with TextArea , but works with other types of dijit when you use Dojo 1.6 and use dijit.form.SimpleTextarea as TextArea . The setValue("") function also does not work.

If this happens to you, try using dojo.byId instead of dijit.byId and just set the value by doing

 dojo.byId("txtAreaMytextarea").value = "somevalue"; 
+2
source share

All Articles