TextField SelectAll Problem ?

I have a form with several Text Fields. All are set to UseFocusRing.

I have the following in each textfield’s GotFocus event: Me.SelectAll

When I tab from field to field any existing text is highlighted whenever the textfield gets focus. However, if I just click on a textfield to give it the focus, any existing text is not highlighted.

I don’t recall having this problem with Real Studio.

Ron Bower

Could this be because clicking with the mouse happens after the select-all code and thus deselects the text? It just happens so fast you can’t see it. You might look at the mousedown event within the textArea and see if you can code around that.

Marc - Good thought. I put the SelectAll code in the MouseDown Event and still no good.

I’m just looking for a way to select all existing text whenever the user clicks on a text field.

Ron Bower

Make sure you return True from MouseDown.

Best Practices would be to…
Place,

me.SelectAll

inside your TextField.SelChange event handler. When you click within a TextField, a cursor positioning changes the “SelStart” property, in turn, firing the SelChange event.

Hope this helps.

[quote=52741:@Ron Bower]Marc - Good thought. I put the SelectAll code in the MouseDown Event and still no good.

I’m just looking for a way to select all existing text whenever the user clicks on a text field.

Ron Bower[/quote]
And you might want to set a flag to prevent running the code once the field is active, so that any subsequent single clicks (like changing the insertion point) don’t select the entire text.

Thanks Mark! forgot that part… which is why MouseDown would not work properly, since MouseDown happens when insertion is performed. (even if a flag was set) :slight_smile:

Best method to prevent over coding, would be to create a TextField Subclass handling this once, then set all TextFields you need this to occur in, Super’s to the subclassed TextField name…

Wow !!! This is getting very complex very fast. Back to studying, I guess.

In MouseDown, use code like

if self.focus <> me then
   me.SelectAll
   return true
end

Here is a demo with a newly created SATextField subclass.

http://www./demos/selectall.xojo_binary_project

Remember… in the current version of the Xojo, MouseDown and HTMLViewers SecurityChanged (WebKit) do not fire properly for Windows builds…

To see the MouseDown bug, create a windows application, use the MouseDown event, return true, and do something in the MouseUp event… Hopefully will be fixed in the next release :wink:

Not sure what OS you are building for, but always try to keep current Bugs, Cross-platform, and best practices in mind…

[quote=52765:@Tim Hare]In MouseDown, use code like

if self.focus <> me then me.SelectAll return true end [/quote]

Tim - With this code I can not even select the text field to have the focus. Mouse clicks in the field seems to be ignored.

I am using Windows 7 Professional.

As Matthew said, it looks like this is a bug in the current Xojo implementation and I’ll just have to wait for it to get resolved.

Thanks to all for all the suggestions.

Ron Bower

To use the subclass I made, copy and paste it to your application, in the inspector, change the TextField Super from TextField to SATextField…no coding required on your part to get it to work :slight_smile: (although you may want to view the subclass to see how it was achieved…)

Aside…is it just me or is there a bad regex in use to determine links in comments? @Toby Zerner please change this

Advanced URLs Regex:
([a-z0-9_\-]{1,5}:\/\/)?(([a-z0-9_\-]{1,}):([a-z0-9_\-]{1,})\@)?((www\.)|([a-z0-9_\-]{1,}\.)+)?([a-z0-9_\-]{3,})(\.[a-z]{2,4})(\/([a-z0-9_\-]{1,}\/)+)?([a-z0-9_\-]{1,})?(\.[a-z]{2,})?(\?)?(((\&)?[a-z0-9_\-]{1,}(\=[a-z0-9_\-]{1,})?)+)?

Matthew -

I loaded your code and looked at it and think I can undetsnad it.

However, when I run the program the text fields work exactly the same - they will highlight existing text when I tab into them but not when I click in them

I did notice that your application was created using Xojo 3.3 and I am using Xojo 3.2 - I’ll have to wait for the upgrade and then come back to this problem.

Ron Bower

[quote=52793:@Ron Bower]Matthew -

I loaded your code and looked at it and think I can undetsnad it.

However, when I run the program the text fields work exactly the same - they will highlight existing text when I tab into them but not when I click in them

I did notice that your application was created using Xojo 3.3 and I am using Xojo 3.2 - I’ll have to wait for the upgrade and then come back to this problem.

Ron Bower[/quote]

I will ask norman about this…

I just upgraded to Xojo 3.3 and still getting the same.

Matthew: Using your example the text fields highlight on a Tab into, but not on a Mouse Click into.

Tim: Using your suggestion I can’t select the text field with a mouse click.

Ron Bower

[quote=52798:@Ron Bower]I just upgraded to Xojo 3.3 and still getting the same.

Matthew: Using your example the text fields highlight on a Tab into, but not on a Mouse Click into.

Tim: Using your suggestion I can’t select the text field with a mouse click.

Ron Bower[/quote]

I have come up with a working version of SATextField with a little “dynamic array” fix… i have tested it in real studio 2012r2 and Xojo 3.1,3.2,3.3 and the beta 4 (to be released) it works immaculately. Here is the new download link. Please confirm or deny that it works. :slight_smile:

http://www./demos/selectallv2.xojo_binary_project

having problem uploading…may be just a sec…

Finally uploaded…internet fluke…