PDA

View Full Version : [OPEN][3.1] Caret / Cursor Position in Editor Grid Textfield



zachext
17 Dec 2009, 3:27 PM
Ext version tested:

Ext 3.1.0 rev 5770-119


Adapter used:

ext


css used:

only default ext-all.css


Browser versions tested against:

IE8
IE6
Opera 10


Operating System:

Vista
WinXP


Description:

After loading an Editor Grid which contains a Textfield, the cursor / caret is positioned at the beginning of the text field the first time the editor is activated. Subsequent activations position the caret at the end of the text field. This behavior is not observed in Firefox 3.5.6 or Safari 4.0.4


Test Case:
See this URL :

1.) http://www.extjs.com/deploy/dev/examples/grid/edit-grid.html

2.) http://www.extjs.com/deploy/dev/examples/grid/row-editor.html


Steps to reproduce the problem:

Using Internet Exlporer or Opera, visit one of the links above and activate a TextField.
In the Editor Grid example, the Common Name field displays the behavior.
In the Row Editor example, either of the First Name or Email fields display the behavior.
After the first activation, the page will need to be refreshed to see the behavior again.


The result that was expected:

The cursor should be positioned at the end of existing text.


The result that occurs instead:

On first activation, the cursor is positioned at the beginning of existing text.


New fix (3.3):



Ext.override(Ext.Element, {
focus: function (defer, /* private */dom) {
var me = this,
dom = dom || me.dom;
try {
if (Number(defer)) {
me.focus.defer(defer, null, [null, dom]);
} else {
dom.focus();
dom.value = dom.value;
dom.focus();
if (dom.sof) {
dom.select();
}
}
} catch (e) { }
return me;
}
});



AND



Ext.override(Ext.form.TextField, {
preFocus: function () {
var el = this.el,
isEmpty;
if (this.emptyText) {
if (el.dom.value == this.emptyText) {
this.setRawValue('');
isEmpty = true;
}
el.removeClass(this.emptyClass);
}
if (this.selectOnFocus || isEmpty) {
el.dom.sof = true;
el.dom.select();
}
}
});



Older fix:
For IE:


Ext.override(Ext.Element, {
focus: function(defer, /* private */dom) {
var me = this,
dom = dom || me.dom;
try {
if (Number(defer)) {
me.focus.defer(defer, null, [null, dom]);
} else {
dom.focus();
}
} catch (e) { }
//begin override
if (document.selection) {
var range = document.selection.createRange();
if (dom && dom.value) {
range.move('character', dom.value.length);
range.select();
}
}
//end override
return me;
}
});
})

zachext
18 Oct 2010, 1:09 PM
With the release of 3.3 , the fix noted above triggers a blur on every other field activation if the field editor is a textarea. Does anyone have ideas about what would cause that?

Thanks