Solved

Flex TextInput

Posted on 2010-11-17
4
1,382 Views
Last Modified: 2012-05-10
How to restrict a TextInput feild from cut copy and paste?
0
Comment
Question by:srujanmiryala
  • 2
4 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34161147
So you just want to write but not cut copy and paste?

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34161153
I have not tried it but why do you try this one:

On de-focus of te component disable the text field.
try overriding the key press events for cut copy and paste for the text filed (not sure if you can override, which also check this out)

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
0
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 500 total points
ID: 34164749
There are a number of options, depending on what you want to do.

If you want to use the TextInput field to display text but NOT to allow the user to edit the text, set the enabled property to false:
<s:TextInput width="175" enabled="false" text="Sample text..." />

Alternatively, if you want to prevent the user from selecting and copying the text set the selectable property to false:
<s:TextInput width="175" selectable="false" text="Sample text..." />

Finally, if you want to prevent pasting into the area, then we have to trap for the Text event. Basically you're looking to see if someone enters more than 1 letter at a time. If so, don't allow it. The reason this works is that when you're typing, each letter fires the event, but if you're pasting, the entire paste operation triggers the event and that would have more than one letter. Of course, if the person wants to paste one letter at a time, this solution will not prevent that...

private function onTextInput(event:flash.events.TextEvent):void
{
  if (event.text.length > 1)
    event.preventDefault();
}

myTextInputField.addEventListener(TextEvent.TEXT_INPUT, onTextInput);

Hope this helps!

T
0
 

Author Closing Comment

by:srujanmiryala
ID: 34164985
Hello tomaugerdotcom,

Thank you very much for the solution. I am using flex 3.0.
so for  textinput selectable property is not there.
i have went with your script code. it worked fine and that helped me a lot with the solution.

Thank you very much.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now