Blocking text changes in fields

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Blocking text changes in fields

Post by golife » Fri Nov 19, 2021 12:13 am

// 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
Last edited by golife on Sat Nov 20, 2021 1:31 pm, edited 1 time in total.

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

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

Post by SWEdeAndy » Fri Nov 19, 2021 9:49 am

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?
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Fri Nov 19, 2021 6:44 pm

Yep - you can for sure select and copy text in a field with lockText on by default.
I use this in some standalones too...

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Fri Nov 19, 2021 7:21 pm

Hi All,
Yes,
locktext to true and traversalon to true
and you can select and copy selected text
Best regards
Jean-Marc
https://alternatic.ch

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: Blocking text changes in fields

Post by golife » Sat Nov 20, 2021 1:35 pm

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
:)

Post Reply