Set Value of Dijit.Form.Textarea

限于喜欢 提交于 2019-12-14 03:45:13

问题


I have a dijit dialog that contains a form that I want to auto-populate. I can get the dialog to display with the form in it, but I have been unable to set the value of a text area within the form. Here is the div that houses the html.

<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 issue I have is setting the value of the textarea called "desc". I have tried multiple things, but I know I need to

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

but if I set any property of test, such as

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

The value is never saved and displayed inside the textarea. Is there a trick to doing this? Any help would be great. Thanks


回答1:


var test = dijit.byId("desc");
test.set("value", "foo");

..should do the trick, I think. Most widgets in Dojo use the set method (formerly attr) to set property values, instead of manipulating them directly like you've tried to do. You can also set multiple properties in one go by passing an object:

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



回答2:


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

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

dojo.byId("txtAreaMytextarea").value = "somevalue";


来源:https://stackoverflow.com/questions/5107722/set-value-of-dijit-form-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!