PDA

View Full Version : [CLOSED] [2.0] AutoFocus question



Timothy
Jun 24, 2012, 10:28 PM
Hello,

Just curious if there is a setting to automatically make the AutoFocus property focus to the end of a text field value instead of at the beginning? I do not want to enable the SelectOnFocus if possible.

Cheers,
Timothy

Daniil
Jun 25, 2012, 1:19 PM
Hi,

There is no such built-in functionality.

I have found this:
http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element

The following appears to be working in IE and Chrome, but no in FireFox.

Example

<ext:TextField runat="server" Text="Hello!" AutoFocus="true">
<Listeners>
<Focus Handler="this.inputEl.dom.value = this.inputEl.dom.value;" />
</Listeners>
</ext:TextField>

To get it working in FireFox I would try to apply the solution form the second answer using setSelectionRange.

Timothy
Jun 25, 2012, 1:25 PM
Thanks! I didn't realize it was a general HTML DOM issue; much appreciated for the suggestion. You can close this one -- as it's not your problem :)

Cheers

Daniil
Jun 25, 2012, 1:33 PM
No problem, it was interesting to investigate since I have never met such requirement. It can be useful in my further practice.

geoffrey.mcgill
Jun 27, 2012, 5:24 PM
The following config might be helpful if you want to move the cursor index to the end of the TextField upon initial render.

Example


<ext:TextField ID="TextField1" runat="server" Text="Testing..."> <Listeners>
<AfterRender Handler="this.selectText(this.getValue().length);" />
</Listeners>
</ext:TextField>

Timothy
Jun 27, 2012, 9:01 PM
The following config might be helpful if you want to move the cursor index to the end of the TextField upon initial render.

Example


<ext:TextField ID="TextField1" runat="server" Text="Testing..."> <Listeners>
<AfterRender Handler="this.selectText(this.getValue().length);" />
</Listeners>
</ext:TextField>

Thanks that worked great.

Cheers,
Timothy