Page 1 of 2
Select text on text field
Posted: Mon Jul 10, 2017 10:53 pm
by simon.schvartzman
Hi, I have a text field with the traversalOn set to true.
I would like the whole text to be selected when the field gets focus.
In other words I would like to replace all the existing text on the field when the user types new text.
I've tried
Code: Select all
on mouseUp
select the text of me
close mouseUp
and (on an iPhone) I can see the text become selected for a short period of time and then the cursor goes to end of the text unselecting the rest of the text.
Any hints as how to do it?
Thanks
Re: Select text on text field
Posted: Mon Jul 10, 2017 11:38 pm
by dunbarx
Hi.
first off, there is no "close mouseUp". You must 'end mouseUp"
I cannot believe this compiled. Anyway, what happens if you change it?
Craig Newman
Re: Select text on text field
Posted: Tue Jul 11, 2017 5:47 am
by shaosean
I think you want to handle that in the "openField" event
Code: Select all
on openField -- when clicking in the field, select all its text
select text of the target
end openField
Re: Select text on text field
Posted: Fri Jul 14, 2017 4:18 pm
by simon.schvartzman
@dunbarx
first off, there is no "close mouseUp". You must 'end mouseUp"
I cannot believe this compiled. Anyway, what happens if you change it?
You are right it doesn't compile as expected (I wrote it instead of copying the code and made the mistake). Anyway behavior doesn't change.
@shaosean
Code: Select all
on openField -- when clicking in the field, select all its text
select text of the target
end openField
it behaves exactly the same way, text is not selected and cursor insertion point remains at the end of the text
Many thanks for both of you for answering, any other hints?
Re: Select text on text field
Posted: Sat Jul 15, 2017 2:35 am
by shaosean
If that code doesn't work, then something is broken and needs to be looked at.. It's Livecode's example code..
Re: Select text on text field
Posted: Sat Jul 15, 2017 2:30 pm
by dunbarx
Hi.
I assume the field is locked and the handler is in its script? Because the handler will work.
Perhaps the issue is the way a locked field acts in comparison to an unlocked one? If the field is unlocked, invoking something like:
Code: Select all
select before text of fld yourField
Will show a blinking cursor at the loc of interest. But in a locked field, this does not appear.
Craig Newman
Re: Select text on text field
Posted: Sat Jul 15, 2017 4:00 pm
by jacque
First, does it work correctly on desktop and only fail on mobile? There are a number of selection issues with LC fields on mobile devices. In general it's best to use native input fields on mobile.
If the problem is also happening in the IDE then something else is wrong.
Re: Select text on text field
Posted: Sat Jul 15, 2017 9:34 pm
by simon.schvartzman
Team may be I'm missing something very basic and hope you could clarify.
With the attached script:
1 - The behavior is exactly the same on the IDE, Simulator and real device (iPhone)
2 - On the IDE if I "enter" the field via "TAB" it works as expected
3 - Entering the field via mouse (IDE and simulator) or finger (iPhone) doesn't select the text
4 - Having or not the field "locked" doesn't make any difference.
5 - I'm using LC 8.1.5 Indy
looking forward for your enlightened inputs...
Re: Select text on text field
Posted: Sat Jul 15, 2017 10:15 pm
by jmburnod
Hi All,
It seems that "send in time" is necessary in this case. It works for me (LC indy 8.1.3).
Code: Select all
on openField -- when clicking in the field, select all its text
set the traversalOn of me to true
-- doSelText the short name of the target-- doesn't work
send "doSelText the short name of the target" to me in 2 milliseconds--works
end openField
on doSelText pFld
select char 1 to -1 of fld pFld
end doSelText
The main question remains... do you can wait 2 milliseconds
Best regards
Jean-Marc
Re: Select text on text field
Posted: Sat Jul 15, 2017 10:28 pm
by jacque
I see. Whatever the engine does after "openField" is sent is causing the selection to disappear. I had to change the script of each field to this:
Code: Select all
on openfield
send "doSelect" to me in 1 millisecond
end openfield
on doSelect
select the text of me
end doSelect
That could be improved by passing the field name to a doSelect handler on the card or somewhere else in the message path.
Edit: Oops, I see I was too slow to respond.

BTW, you don't need to set traversalOn, it's persistent.
Re: Select text on text field
Posted: Sun Jul 16, 2017 2:34 am
by shaosean
This should be reported as a bug..
Re: Select text on text field
Posted: Sun Jul 16, 2017 3:10 am
by PBH
I'm not sure this would be classed as a bug, because it looks to me like the engine is controlling "normal" behaviour. i.e. Normally when you click in a field the insertion point is placed at the point where you click with the cursor, so this is cancelling the select text script immediately after the mouse is released. I went back to LC 5.5.5 and it shows the same behaviour.
If you click ON the text, you will see the text become selected momentarily and then it is de-selected as the mouse button is released, unless you move the cursor away from the text before releasing the mouse button, in which case the text stays selected.
No mouseUp message is received by the field, card or stack so I think the engine is using the mouseUp to set the insertion point to where it would normally be expected, I think this also explains why send in time works, but another option is to check for selectionChanged, because that's exactly what happens when the mouse is released, this works reliably for me;
Code: Select all
on openField
selectAllText
end openField
on selectionChanged
selectAllText
end selectionChanged
command selectAllText
select the text of me
end selectAllText
Re: Select text on text field
Posted: Sun Jul 16, 2017 4:21 am
by jacque
No mouseUp message is received by the field, card or stack so I think the engine is using the mouseUp to set the insertion point to where it would normally be expected, I think this also explains why send in time works, but another option is to check for selectionChanged, because that's exactly what happens when the mouse is released, this works reliably for me
Mouse messages aren't sent in an unlocked field unless it's a right click. I agree though this doesn't sound exactly like a bug, even if it sort of looks like one.
I hadn't thought of using selectionChanged, good idea.
Re: Select text on text field
Posted: Sun Jul 16, 2017 7:04 am
by shaosean
Just because something has worked a particular way for a while, doesn't mean it's not a bug

This is either a bug because the insertion caret should be handled before the openField (for exactly this situation) or it's a documentation bug, as the sample code I posted earlier was directly from the API documentation, on the LiveCode.com website..
Re: Select text on text field
Posted: Sun Jul 16, 2017 8:04 am
by richmond62