Opened 7 years ago

Closed 7 years ago

#16460 closed defect (invalid)

Can't set Editor's content without a delay

Reported by: persilj Owned by: persilj
Priority: undecided Milestone: tbd
Component: Editor Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

I'm forced to use setTimeout, even when the the onLoadDeferred event does fire (see the third part of the provided code) and set the delay to be atleast one second, which is actually quite unbearable (delay is too long and it leaves a feeling that setting the value might still fail).

In the documentation of the Dojo it is mentioned that dijit/editor "uses an iframe to separate the document being edited from the rest of the content" and that "because of it being iframe isolated, the editor initializes asynchronously". Thus one should use Dojo's Deferred implementation, if the purpose is to fill the editor's content area with some text right after the editor-widget has been constructed. However, this doesn't seem to function like I'm willing to believe that it should.

From the 3 mainstream browsers (IE, Chrome and Firefox) this seems to occur only with the latest Firefox (v17, maybe earlier ones, too, using Windows Vista). With IE and Chrome I need no extra delay.

// REMOVE THE EARLIER FORM FIELDS

var widgets = dojo.query("[widgetId]", "formfields").map(dijit.byNode);
dojo.forEach(widgets, function(w) {
  w.destroyRecursive(false);
});
domConstruct.empty("formfields");

// SETUP NEW FORM FIELDS

var formfieldsStr = domConstruct.toDom("<textarea id=\"descriptionfield\"></textarea>");
domConstruct.place(formfieldsStr,"formfields");
var textarea = new Textarea(
  {
    name : "descriptionfield",
    value : ""
  }
}, descriptionfield);

// FILL FIELDS WITH CONTENT

var descriptionfield = dijit.byId("descriptionfield");

descriptionfield.onLoadDeferred.then(function() {
  setTimeout(function() {
    descriptionfield.set("value", "sdfgsdhfghdgfhgdh");
  }, 1000);
});

Attachments (3)

editortestcase2.jsp (2.5 KB) - added by persilj 7 years ago.
Editor wrapped inside a form and a bordercontainer, uses deferred (works ok)
editortestcase3.jsp (1.4 KB) - added by persilj 7 years ago.
Setting programmatically built Textarea's content requires a delay
editortestcase5.jsp (1.3 KB) - added by persilj 7 years ago.
Setting programmatically built Textarea's content (works, uses Deferred and postCreate)

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by bill

Owner: changed from bill to persilj
Status: newpending

I'm confused by your bug report. The summary is talking about Textarea, but then in the description you are talking about the Editor.

Please attach a test case using the "attach file" button. It should be as small as possible to still reproduce the problem, but more than a code snippet like you attached above.

Then, give exact instructions on how to reproduce the problem using your attached test file.

The test case is necessary both to confirm that there's a bug, and for us to be able to debug the problem.

Thanks!

Changed 7 years ago by persilj

Attachment: editortestcase2.jsp added

Editor wrapped inside a form and a bordercontainer, uses deferred (works ok)

comment:2 Changed 7 years ago by persilj

Status: pendingnew

Attachment (editortestcase2.jsp) added by ticket reporter.

comment:3 Changed 7 years ago by persilj

I'm glad you corrected my mistake about the Textarea. Textarea has actually nothing to do with this. Can the title of this be edited, as this is related just to the Editor?

However, I tried to approach my problem gradually by starting with the Editor and adding content to it by using its set-method via onLoadDeferred-method. Kind of sadly, this worked just fine without need for extra delays. I also tried with the dojo.Deferred's "then". This worked just fine, too.

Problem still exists in the actual web service of mine, but I wanted to clarify what works, before going further with my investigations. As my Dojo-based web service has an Editor wrapped inside titlepane and bordercontainer, I added them to the test case, too, but that didn't really make any difference.

In actual web service, I really am forced to set extra delay of atleast 600 milliseconds. Otherwise content won't be set. My intuition tells me that this has something to do with some kind of race condition, as there are no errors to be seen in the Firebug's console.

I'll have to try, if something interferes the setting of the content. Multiple tasks gets done after I press certain button like destroying and rebuilding of certain (other) widgets, toggling of visibilities (bordercontainer's region and individual elements) and loading of content to other widgets (grids, etc.). If that doesn't lead to anywhere, I'm not quite sure, what to try next.

Changed 7 years ago by persilj

Attachment: editortestcase3.jsp added

Setting programmatically built Textarea's content requires a delay

comment:4 Changed 7 years ago by persilj

I think I might have nailed something here (don't change the title just yet, as this seems to be related to both, Textarea and Editor). I've isolated the problem with Textarea and it might give some things about what is problem with setting the content, when Editor is used instead (even when it is a different kind of beast).

Here's 3 variations, from which only one works.

1. Using setTimeout with a delay of 600 milliseconds (result: content will be set just fine)

var descriptionfield = dijit.byId("descriptionfield");

var def = new dojo.Deferred();
def.then(function(descriptionfield) {
  setTimeout(function() {
    var descriptionfield = dijit.byId("descriptionfield");
    descriptionfield.set("value", "dfgdfgd");
  }, 600);
});
def.resolve(descriptionfield);

2. Using setTimeout with delay of 0 milliseconds (result: content will not be set and variable 'descriptionfield' will be null resulting error in Firebug's console)

var descriptionfield = dijit.byId("descriptionfield");

var def = new dojo.Deferred();
def.then(function(descriptionfield) {
  setTimeout(function() {
    var descriptionfield = dijit.byId("descriptionfield");
    descriptionfield.set("value", "dfgdfgd");
  }, 0);
});
def.resolve(descriptionfield);

3. Not using setTimeout (result: content will not be set and nothing implicates about any kind of error)

var descriptionfield = dijit.byId("descriptionfield");

var def = new dojo.Deferred();
  def.then(function(descriptionfield) {
    var descriptionfield = dijit.byId("descriptionfield");
    descriptionfield.set("value", "dfgdfgd");
});
def.resolve(descriptionfield);

Have I somehow understood wrong, how Deferred works? The 'then' method should only be triggered, after widget width an id 'descriptionfield' becomes available? Isn't this what def.resolve is used for?

Changed 7 years ago by persilj

Attachment: editortestcase5.jsp added

Setting programmatically built Textarea's content (works, uses Deferred and postCreate)

comment:5 Changed 7 years ago by persilj

Seems like I had carried away with my thoughts and I kind of guessed how Deferred propably works. Test case 5 shows, how it should have been used -- or is at least enough for me -- without need for any extra delays. I also took some time to read about lifecycle (link1, link2) of widgets and that lead me toward the actual solution. Practically, I had to define the postCreate-method for the Textarea and put deferred.resolve into it.

var textarea = new Textarea({
  postCreate : function() {
    deferred.resolve("dgdfgdfgdfg");
  }
}, "descriptionfield");

I'm aware that this isn't anymore about a possible defect relate to setting content of a Textarea-widget, but I wanted to clarify what I had done wrong, in case somebody finds himself in a similar position (before understanding what he/she hadn't quite grasped).

However, I feel that there is still something strange about the Editor and that is a different kind of issue, as new widgets aren't created (only the content is tried to set). I guess that I'll write something about that one, too, if it doesn't bother anyone?

comment:6 Changed 7 years ago by bill

Component: DijitEditor
Status: newpending
Summary: Can't set Textarea's content without a delayCan't set Editor's content without a delay

OK, so can you provide a test case for Editor that should work but is failing?

By the way, there's no reason to use a Deferred at all in conjunction with a Textarea. It's creation in synchronous.

comment:7 Changed 7 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.