Login Register

Editor replaceValue forces focus

I'm trying to use dijit.byId('id').replaceValue(newValue) to programmatically change the value of a dijit Editor; it works fine except that replaceValue sets the focus to the editor it is changing. This is a problem in the project I am working on as I have attached an onblur event to a number of the editors I dynamically generate (see this forum post for the crazy workaround I had to concoct to get that to work as dojo.connect doesn't seem to handle the editor object sensibly) so that the update content function only fires once the user has focused on another editor object. In using replaceValue (which I'd prefer to use as it maintains the undo/redo integrity) the focus is suddenly brought back to the editor the client had just clicked away from - this causes two issues: first, they have to click away again to go back to the new editor field they clicked on that triggered the onblur event for this first editor field, and secondly, this causes what amounts to an infinite loop (they click on editor1, do some editing, click on editor2 which triggers editor1.onBlur, replaceValue updates editor1.value and then refocuses on editor1, the client clicks back to editor2 to resume editing this field which triggers editor1.onBlur again, ad finitum). I worked around this second issue by doing some unnecessary checks to see if the editor content has changed at all and to only trigger the update function if this is the case, but the first issue still remained. I eventually found out that by using setValue I could update editor1.value without refocusing on it - which makes the fix needed to break this infinite looping unnecessary, thankfully. However, setValue doesn't preserve undo/redo integrity! I'm assuming that there is no way for me to both avoid setting focus to the editor that gets editor.replaceValue and preserve undo/redo but I think this is a serious issue with replaceValue. From looking at RichText.js, I see this:

execCommand: function(/*String*/command, argument){
     ...
		//focus() is required for IE to work
		//In addition, focus() makes sure after the execution of
		//the command, the editor receives the focus as expected
		this.focus();

     ...

}

Now obviously it is the this.focus() call that is causing the behaviour I don't want here, and seemingly it is necessary for IE and according to the documentation, "as expected"; however, I don't see how focusing after execCommand should be "expected" - or, even if it is, there should be a way to override this behaviour to not focus on execCommand. I'm not sure if I'm out in left-field with this application, but it seems to be the idea that you have two editors, and when you go from one to the other, it triggers a save for editor1 while at the same time preserving the undo/redo and respecting the fact that the client just clicked on editor2 and doesn't want the save & update to move the cursor back to editor1.

If any people on the actual Dojo team see this, I would be more than happy to update the Dijit core (really it'd be in RichText.js) to allow for this functionality without having to do all the dirty hacks I've been forced to do; I'd have to discuss with somebody the IE issues that seemingly require focus() so that I could figure a way around that, as well as discuss how one could specify noFocus & still fit dojo command specs (eg, something like dijit.byId('myEditor').replaceValue(newValue,noFocus) or .noFocusReplaceValue(newValue) or whatever) as I've never worked on the Dojo core for public use (I've hacked the hell out of editor plugins and toolbar stuff, as well as dijit behaviour for my own servers but didn't intend for any of those hacks to be for public use so followed my own conventions mostly).

Anyhow, the point with this post is to point out that I had to use setValue instead of replaceValue which causes irritating behaviour, and that I'd like to get in contact with somebody working with the Dojo project to see how I might go about fixing this problem as well as the [much more irritating] issue I detailed here: http://www.dojotoolkit.org/forum/dijit-dijit-0-9/dijit-support/dojo-conn...

Thanks