How to override the dojo control focus method on FF

1.6k Views Asked by At

We have an existing application using dijit controls. The previous behavior on pre FF6 when the control is focused is it also gets selected. However, starting FF6 the control is no longer selecting all text. The problem now is there are a lot of dojo.byId('ctrlId').focus() in our code. I can fix that by adding a dojo.byId('ctrlId').select() code after each focus call. but I am looking for a more global way to fix this.

I tried overriding the focus method but it does not work.

HTMLFormElement.prototype._select = HTMLFormElement.prototype.select;
dijit.prototype.focus = function() {
    this.focus.apply();
    this.select.apply();
}

Any ideas?

1

There are 1 best solutions below

1
On

Firstly, you should be using dijit.byId not dojo.byId. Dijits are complex classes and using dijit.byId will ensure you are targetting the right thing.

Secondly, which Dijit are you using? You can see a list here: http://dojotoolkit.org/api/1.6/dijit/form

Thirdly, I'm not entirely sure what you mean by "when the control is focused is it also gets selected". Do you mean the text inside the dijit is selected?

Assumig we're dealing with a dijit.form.TextBox, how about catching the focus event and forcing a select? Something like this:

dojo.connect( dijit.byId('ctrlId'), 'focus',  function() { dojo.query( 'input', dijit.byId('ctrlId' ).domNode )[0].select() } );

(I've not tested this but you get the idea I hope.)