Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 11:14 am
I have a field that I want to prevent user from manually editing. But I want to allow free movement of cursor, selection of text and copying.
First of all is there a simple way of doing this? If not, I have put in a number of handlers to prevent editing:
Code: Select all
on arrowkey
pass arrowkey
end arrowkey
on keydown
exit keydown
end keydown
on deletekey
exit deletekey
end deletekey
on backspacekey
exit backspacekey
end backspacekey
on cutkey
exit cutkey
end cutkey
on pastekey
exit pastekey
end pastekey
on returnInField
enterInField
end returnInField
on enterInField
exit enterInField
end enterInField
Works pretty well, but
cutkey and
pastekey are not preventing cut and paste, even when I Suspend Development Tools, as suggested in the dictionary.
Any suggestions?
Kaveh
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Apr 27, 2019 12:08 pm
Did you test in a standalone?
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Sat Apr 27, 2019 12:15 pm
Hi,
A quick and dirty solution
Field Script:
Code: Select all
on openfield
set the uMyText of the target to the text of the target
end openfield
on textChanged
put the uMyText of the target into me
end textChanged
Best
Jean-Marc
Last edited by
jmburnod on Sat Apr 27, 2019 12:16 pm, edited 1 time in total.
https://alternatic.ch
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 12:16 pm
Yes. Problem persists in standalone on Mac OS X
Kaveh
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 12:20 pm
Jean-Marc
I thought of something like your solution. Thanks, that is good to know.
But problem is there is a lot formatting (saved as htmltext) and in addition I want the user to see minimal interruption, so they need to have same vscroll and selectedtext. So ideally want the cut and paste commands to simply not do anything. Works great with other keys that simply disappear silently.
Kaveh
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Apr 27, 2019 12:54 pm
kaveh1000 wrote: ↑Sat Apr 27, 2019 12:16 pm
Yes. Problem persists in standalone on Mac OS X
Then I consider this a bug!
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Sat Apr 27, 2019 1:11 pm
kaveh1000 wrote: ↑Sat Apr 27, 2019 11:14 am
I have a field that I want to prevent user from manually editing. But I want to allow free movement of cursor, selection of text and copying.
First of all is there a simple way of doing this?
The simplest of all would be to lock the text, and leave transversal on, if I understood the question right

- Lock me up, before you go go...
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 1:47 pm
Hi Bogs
I want to be able to use arrowkeys, e.g. with shift key and select text. And to scroll around as normal text. With locked text I can't do that and can't even see text cursor.
Kaveh
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Sat Apr 27, 2019 2:12 pm
Says who? You won't see the cursor, but you still will be able to select using the arrow keys and shift, ctr./shift, etc.
https://youtu.be/RyaYVoe7buI
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 2:24 pm
OK. I didn't know that even though the cursor is not visible the system knows where the cursor is. Thanks for taking the time to produce the video.
But that itself is a major disadvantage. A user will be used to seeing the cursor with pressing arrow keys so they know where they are. I want the behaviour to be the same as other fields on a card.
Kaveh
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Sat Apr 27, 2019 4:09 pm
Well, you could handle this in a hundred different ways probably. The simplest would be to intercept the raw key messages, and only allow certain control/cmd key combos through. The kludgiest would probably be to stick a regular field above the locked one, stick the text from the locked one into it, and then you would have your cursor and like that. You'd have to direct allowable actions down to the locked field, like copying, but any other actions would have no effect on the locked field.
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sat Apr 27, 2019 6:05 pm
I was thinking of something like bogs suggested. The pasteKey function has been iffy for years, but you can trap commandKeyDown and only pass the message if the key is C.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sat Apr 27, 2019 7:41 pm
I wonder if it would be simpler file an enhancement request to have the insertion cursor visible with any selectable field regardless whether its locktext is true or false.
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Apr 27, 2019 8:49 pm
Hi folks
Thank you for all the ideas. The solution that seems to work is that I save the following parameters of the field:
When the user cuts or pastes any text, a dialogue box pops up to warn them they cannot change text, and then the parameters of the field are reset, and they are back where they were.
@Richard, I think that all that is needed is that the text cursor is shown even in a locked field. Great idea. A simple but useful addition. Do I make this suggestion through the bugs page?
Kaveh
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sat Apr 27, 2019 8:59 pm
Yes. Please post the resulting URL here so we can follow along.