Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Disable Copy Paste in InputText

New Here ,
Oct 02, 2009 Oct 02, 2009

Someone know Know How to disable copy/paste inside Flex InputText control?

I have Flex 3.2 SDK.

Thanks

TOPICS
Flex SDK
5.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 18, 2010 Nov 18, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2013 Jun 19, 2013

   Hi,tomaugerdotcom !

    

        I found that it is not right.I think it can't achieve the desired effect by experiment.If the user use the right mouse button to paste or use "Ctrl + V" that will not be able to capture "TextEvent. TEXT_INPUT".

   I have flex 4.5 SDK.

 

     Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2013 Jun 19, 2013
LATEST

private var oldTxt:String="";

           

            protected function txtIpt_changeHandler(event:TextOperationEvent):void

            {

                var s:String=(event.currentTarget as TextInput).text;

                var n:Number=Number(s);

                if(!isNaN(n))

                {

                    var newS:String=s.substring(oldTxt.length,s.length);

                    if(newS.length>1)

                    {

                        txtIpt.text=oldTxt;

                    }else

                    {

                        txtIpt.text=s;

                    }

                }else

                {

                    txtIpt.text=oldTxt;

                }

                oldTxt=txtIpt.text;

                trace(txtIpt.prompt);

            }

myTextInputField.addEventListener(TextOperationEvent.CHANGE, txtIpt_changeHandler);

You can use this method!

I wish you good luck!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines