Paste into a text entry field

Ken Ray kray at sonsothunder.com
Sun Dec 18 19:48:23 EST 2005


On 12/18/05 4:55 PM, "Flavel Steve" <stevef at upnaway.com> wrote:

> Hi,
> I have another basic question.
> 
> I have multiple text entry fields with filtered key entries, for
> example only accepts numbers of length less than 10.
> 
> However any paste is accepted.  I would like to keep cut and paste
> between fields.  And if this was the only copy and paste allowed it
> would be OK.  But at the moment I can copy anything and paste it into
> the text field.
> 
> What is the best way to filter pastes in this situation?

Trap the 'pasteKey' message, and then look at the clipboardData["text"] to
determine what to do. Look at the Transcript Dictionary entry for 'pasteKey'
to see an example of replacing returns with spaces in the clipboard.

As to knowing whether the text in the clipboard came from your app or
somewhere else - I'm not sure if that's innately possible. You may need to
set some flag when you do a copy and then check the flag when you paste to
see if it is "on".
 
> Also is it possible to not allow cut and paste on a text entry field?

Sure. Just trap the pasteKey message and don't pass it.

Note that the pasteKey message is only triggered by keyboard - if someone
chooses "Paste" from one of your menus, you'd have to put a similar
"check-and-pass" trap in your menu code.

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list