How To Ensure Only Plain Text Editing Is Allowed In Field
    Cubist at aol.com 
    Cubist at aol.com
       
    Fri May 12 15:07:09 EDT 2006
    
    
  
>Ivan Wong wrote...
> Is there any easy way (beyond trapping and disabling unwanted keystrokes),
> to allow users to only edit in plain text, and keep editing to a single 
line 
> in text fields.
   This doesn't strike me as all *that* difficult to pull off; the following 
code should work, or at least provide a pointer to the true solution. Watch 
out for extra-long lines here...
local TimeDelay = .2
local MaxFieldLength = 30
on openField
  set the PlainOnly of me to true
  send "KeepItSimpleStupid" to me in TimeDelay seconds
end openField
on closeField
  set the PlainOnly of me to false
end closeField
on exitField
  set the PlainOnly of me to false
end exitField
on KeepItSimpleStupid
  put the selectedChunk into Fred
  
  if (the length of me > MaxFieldLength) then put char 1 to MaxFieldLength of 
me into me
  if (the textStyle of char 1 to -1 of me <> "plain") then put me into me
  if (the textColor of char 1 to -1 of me <> "black") then set the textColor 
of char 1 to -1 of me to "black"
  
  if (the selectedChunk <> Fred) then select Fred
  
  if (the PlainOnly of me) then send "KeepItSimpleStupid" to me in TimeDelay 
seconds
end KeepItSimpleStupid
   The local variable TimeDelay controls how often the KeepItSimpleStupid 
handler will fire; the value i used here, .2, means KeepItSimpleStupid will run 
five times a second. Adjust TimeDelay up or down if you want a different number 
of times per second.
   The local variable MaxFieldLength controls how long the field *can* be. 
Any time the field gets longer than MaxFieldLength, the 'excess' characters are 
summarily deleted in KeepItSimpleStupid.
   Hope this helps...
    
    
More information about the use-livecode
mailing list