Make the field clickable by setting lockText to true on exiting field
Then on mouseDown reverse this and set the selection
Just by manipulating lockText, the cursor appears at the start of the text if showing the placeholder text, or hilites the entire text if it contains a real string. I knew this must be possible... Phew!
(there is the even more minor issue that if the user has entered the field and and then decides to click and hold the mouse the same minor issue again occurs - but I'll let that one go )
Code: Select all
on mouseDown
set the lockText of me to false
if fieldIsEmpty() then
select before me
else
select the text of me
end if
end mouseDown
Code: Select all
on exitField
setTextStyle
if fieldIsEmpty() then set the text of me to the uPlaceholderText of me
set the lockText of me to true
end exitField
on closeField
exitField -- thanks for the tip Paul :)
end closeField
The remaining question (to which is suspect the answer to will be 'No"):
if the field text is changed in script is it possible to react automatically to this? (i.e. if the field is showing it's placeholder text and I assign a string to this, how can I get it to trigger an update without firing a second command - in my case exitField - to do this?)
textChanged won't fire if text set by script
setProp is only available for custom properties
Is there way of trapping the "set text" message so a handler can update automatically? (again no biggie if not possible, will just send exitField to the field - but would have been nice to fully encapsulate all functionality in a single standard command).