0

How can I set the content of a dijit.editor after it has loaded?

The following is a solution but I am using <script type='dojo/method'> a lot because crome and opera don't like dojo.connect(nodeId, 'onclick', function(){ ... }); (though firefox seems happy). I tried <script type="dojo/method" event="onLoadDeferred"> but it just threw up an error.

Any ideas?

EDIT

If you can't load content into an editor how are you surposed to used it to update content?

3
  • I tried using this.replaceEditorContent(...) from here without much sucess Commented Sep 12, 2011 at 11:36
  • Can you post what your html markup looks like? Commented Sep 12, 2011 at 12:17
  • It's nothing special just simple <div rows="10" dojoType="dijit.Editor" name="letter_header" id="editor_letter_header"> Commented Sep 12, 2011 at 13:29

1 Answer 1

1

This might be a stupid answer, but have you simply tried putting the value inside the declaration of the dijit.Editor?

For example:

<body class="claro">
    <div data-dojo-type="dijit.Editor" id="myEditor">
        This is the initial value of the editor
    </div>
</body>

This will create the editor and set the value of the editor to be whatever text is inside the dijit.Editor markup ("This is the initial value of the editor").

If you need to programmatically change the value of the editor AFTER it has loaded, it seems like you can just use editor.set('value', 'some new text');

For example:

<body class="claro">
    <div data-dojo-type="dijit.Editor" id="myEditor">
        This is the initial value of the editor
    </div>

    <div data-dojo-type="dijit.form.Button">
      Click to change editor value
       <script type="dojo/method" event="onClick">
           var editor = dijit.byId('myEditor');
           editor.set('value','this is the new value');
        </script>
    </div>
</body>

I put together the working sample above in a jsfiddle

http://jsfiddle.net/Vu4NF/1/

3
  • That does work but I have a problem with submitting the content (I think its something to do with an iFrame). My post data does not show the content of the editor, so I am loading it into a hidden field and then putting that data in the editor for loading and then copying the contents of the editor into a hidden field when it is submitted Commented Sep 12, 2011 at 14:24
  • The editor does use an iframe which would prevent it from being submitted with the rest of the form. One way of solving this (as described at stackoverflow.com/questions/6073811/…) is to use dojo/method event="onChange" to populate the hidden field as you type in the dijit.Editor. Another useful question for submitting the dijit.Editor values: stackoverflow.com/questions/6695581/… Commented Sep 12, 2011 at 14:52
  • I have marked this as the right answer because I'm using dojo/dojango/django the answer is a mixture of the above using hidden fields, a onChange function and a customSave in forms.py. Commented Sep 13, 2011 at 13:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.