How do I prevent text fields from accepting formated text?

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
makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

How do I prevent text fields from accepting formated text?

Post by makeshyft » Fri Jul 12, 2013 8:01 pm

Hello Livecode geniuses

How do I prevent a text field from accepting html text ... with colors and bolds and etc..... when pasting into a field? I want plain text only.

Thanks,
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How do I prevent text fields from accepting formated tex

Post by FourthWorld » Fri Jul 12, 2013 8:41 pm

See the "clipboardData" property in the dictionary.

By default the "paste" command will preserve as much of the richness of pasted content as possible, but you can make more specific choices by obtaining the clipboardData contents directly.

The clipboardData is an array, which for text contains multiple forms accessed through its keys, including "htmlText" and simply "text".

To put only the unstyled text into a field:

Code: Select all

put the clipboardData["text"] into fld "MyField"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: How do I prevent text fields from accepting formated tex

Post by makeshyft » Fri Jul 12, 2013 8:42 pm

Great....thanks Richard!
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How do I prevent text fields from accepting formated tex

Post by Klaus » Fri Jul 12, 2013 10:57 pm

Hi Tom,

sounds more like you wnat to prevent the user from PASTING styled text into a field, right?
In that case you can script a "on pastekey" (see dictionary) handler in your field, which removes the "styled" from the text :-)

Hint:
This does NOT work in the IDE, only in the resulting standalone.
Obviously the IDE "catches" this by itself :-D


Best

Klaus

makeshyft
Posts: 222
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: How do I prevent text fields from accepting formated tex

Post by makeshyft » Sat Jul 13, 2013 12:18 am

Roger that! Thanks Klaus!
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

Post Reply