Solved

Flex TextInput

Posted on 2010-11-17
4
1,396 Views
Last Modified: 2012-05-10
How to restrict a TextInput feild from cut copy and paste?
0
Comment
Question by:srujanmiryala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Invest in your employees with these five simple steps to improve employee engagement and retention.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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