Limiting field entry to plain text
Peter M. Brigham, MD
pmbrig at gmail.com
Thu Oct 27 14:16:19 EDT 2011
It occurred to me a little belatedly that someone might be interested in a handler I use for pasting unformatted text (so that it matches the text formatting of the target field). I have this in my LC frontscript, so it's available to me everywhere in LC:
on commandKeyDown pKey
-- command-control-V pastes plain text
-- (to match the formatting of the target field)
if pKey is not "V" then pass commandKeyDown
if the controlKey is up then pass commandKeyDown
-- cmd-ctrl-V only
if the tool is not "browse tool" then pass commandKeyDown
if the clipboard is not "text" then pass commandKeyDown
if the selectedField is empty then pass commandKeyDown
if the long name of the target contains "revNewScriptEditor" \
then pass commandKeyDown
-- other cases are now filtered out,
-- plain text is needed
set the HTMLText of the templatefield to the clipboardData["HTML"]
if the autoTab of the selectedField then
get the text of the templatefield
replace return with space in it
set the text of the templatefield to it
end if
set the clipboardData["TEXT"] to the text of the templatefield
reset the templatefield
paste
end commandKeyDown
Very handy thing to have available, I have found. This will need tweaking for a Windows platform, given the differences in commandkey/controlkey handling c/w OSX. Just alter it to use another modifier key combo as needed.
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
On Oct 25, 2011, at 4:51 PM, John Brozycki wrote:
> Thanks, Terry and Klaus for responding. I used Klaus' recommendation.
>
> Sure enough, there WAS a better way!
>
> On Oct 25, 2011, at 3:46 PM, Klaus on-rev wrote:
>
>> Hi John,
>>
>> Am 25.10.2011 um 21:05 schrieb Terry Judd:
>>
>>> On 26/10/2011, at 05:51 AM, John Brozycki wrote:
>>>
>>> Hi all,
>>>
>>> I have an input field that accepts URLs. If a user copies a URL from an email or a website and pastes it, it is pasted in HTML format. I only want the field to be plain text. I can set the font and size, but it seems like fields always exist with (plain)text and htmltext states and LiveCode automatically accepts htmltext when it's entered. Is there a setting to make a field ONLY plaintext, even if a user copies and pastes a URL from an email or browser?
>>> My current workaround is to trap the paste function for the field, then paste and convert it, which happens instantaneously from a user standpoint:
>>>
>>> on pasteKey
>>> paste
>>> set the htmltext of field "URLField" to the text of field "URLField"
>>> end pasteKey
>>
>> try this:
>> on pasteKey
>> put the clipboarddata["text"] into fld "URLField"
>> end pasteKey
>>
>> Check "clipboarddata" in the dictionary.
>>
>>> So, this works, but I was wondering if there is a way to limit a field to only plaintext so I wouldn't have to do this. Any recommendations appreciated.
>>> Much of a muchness, but you could try clearing the clipboardData["html"] before you paste in your pasteKey handler. That way you should just be pasting plain text.
>>> Terry...
>>>
>>> Thanks,
>>> John
>>
>> Best
>>
>> Klaus
>>
>> --
>> Klaus Major
>> http://www.major-k.de
>> klaus at major.on-rev.com
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list