Page 1 of 1

Blocking text changes in fields

Posted: Fri Nov 19, 2021 12:13 am
by golife
// CHANGED //

Here is a little code snippet (for beginners) in case someone needs to allow users to select text and copy the selected text, but not allow any changes to the text, or depending on allowing a rawkey number to be passed but only within a certain range.

This is often needed when a data record is loaded in "Data Browse" mode.

Code: Select all

on rawkeydown k
   if the controlkey is down then
      if k = 99 then -- k = 99 is the key "c"
         set the clipboarddata["text"] to the selectedtext
      end if
   end if
end rawkeydown

Code: Select all

## Allow users to copy locked text using mouseDown
/* Script of a text field (or behavior, or group, card, stack...)
The field's 'locktext' property is set to true.
A locked field receives "mouseDown/mouseUp" messages. */

on mouseDown
    set the clipboarddata["text"] to the text of me -- or 'the target', or give the name or id of the field
end mouseDown
Have fun... Roland

Re: Blocking text changes in fields but allowing text selections and copy

Posted: Fri Nov 19, 2021 9:49 am
by SWEdeAndy
golife wrote:
Fri Nov 19, 2021 12:13 am
If we set the 'locktext' property of a field to true then no text selection is possible
without some scripts.
Quite the contrary - setting the lockText of a normal field to true does not prevent selecting and copying. No code needed at all for that. At least in the IDE, but I don't remember it being different in standalones. autoHilite and traversalOn ("Focus with keyboard") need to be set to true though, otherwise selecting and copying is indeed prevented.

What am I missing?

Re: Blocking text changes in fields but allowing text selections and copy

Posted: Fri Nov 19, 2021 6:44 pm
by stam
Yep - you can for sure select and copy text in a field with lockText on by default.
I use this in some standalones too...

Re: Blocking text changes in fields but allowing text selections and copy

Posted: Fri Nov 19, 2021 7:21 pm
by jmburnod
Hi All,
Yes,
locktext to true and traversalon to true
and you can select and copy selected text
Best regards
Jean-Marc

Re: Blocking text changes in fields

Posted: Sat Nov 20, 2021 1:35 pm
by golife
THANK YOU ALL FOR THE COMMENTS WHICH ARE CORRECT.

I changed the explanation of the original entry for that reason to not mislead anybody.

I am sorry. It never really occurred to me that it was in fact possible to select text of a locked field
even after 10 years of working with LC. I always only used to disallow access to the field, or to allow mouseDown/up messages, etc.

There is something new to learn every day... )))

:oops: :oops: :oops:

Roland
:)