6 Replies Latest reply on Jan 3, 2011 3:30 AM by Sepeleu

    Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It

    kiran7881 Level 1

      Hi ,

       

      I have a TextInput . I want it to have a Default Value as  "Search " , so made it this way

       

      <mx:TextInput x="1050" y="10"  fontFamily="Verdana" fontSize="15  text="Serach" />

       

      Now When ever the User clicks on textInput , how can i clear this default  Search??

       

      I have tried this way ,but its not working but infact throwing a Compile Timer Error showing this :

       

      Initializer for 'mouseEnabled': cannot parse value of type Boolean from text 'clearTI()'.\

       

      This is my code :

       

      <mx:TextInput id="MyTI" x="1050" y="10" text="Serach"   mouseEnabled="clearTI()" />

       

      public function clearTI():void
              {
                  MyTI.text='';
              }

       

       

      Please help me out . Thnaks .

        • 1. Re: Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It
          Sepeleu

          Hi, I realise the same things with Flex 4, but it's almost the same, just modify namespace and states management.

           

              <components:CustomTextInput id="password_ti" width="100" displayAsPassword="true" text="@{this.password}"
                                       change="{checkPassword()}" enter="getConnection()"
                                       defaultText="{resourceManager.getString('gencore_login','gencore.login.module.password')} "/>

           

          My CustomTextInput.mxml

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   initialize="onInit(event)"
                   focusIn="textinput1_focusInHandler(event)"
                   focusOut="textinput1_focusOutHandler(event)"
                   focusEnabled="true"
                   text.STATE_VIEW="{defaultText}"
                   text.STATE_EDIT=""
                   color.STATE_VIEW="0xC8BBBE"
                   color.STATE_EDIT="black"
                   displayAsPassword.STATE_VIEW="false">
             
              <fx:Declarations>
                 
              </fx:Declarations>
             
              <fx:Script>
                  <![CDATA[
                      import mx.events.FlexEvent;
                     
                      [Bindable]
                      public var defaultText:String = "";
                     
                      protected function onInit(event:FlexEvent):void
                      {
                          this.currentState = "STATE_VIEW";
                      }

           

                      protected function textinput1_focusInHandler(event:FocusEvent):void
                      {
                          this.currentState = "STATE_EDIT";               
                      }
                     
                      protected function textinput1_focusOutHandler(event:FocusEvent):void
                      {               
                          if ( text == "" ) {
                              this.currentState = "STATE_VIEW";
                          } else {
                              this.currentState = "STATE_EDIT";
                          }           
                      }

           

                  ]]>
              </fx:Script>
             
              <s:states>
                  <s:State name="STATE_EDIT"/>
                  <s:State name="STATE_VIEW"/>
              </s:states>
             
          </s:TextInput>

          • 2. Re: Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It
            kiran7881 Level 1

            Thank you very much for the help .

             

            I dont wan to write such a long code , is there any simple function for doing so ??

             

            • 3. Re: Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It
              Sepeleu Level 1

              I searched long time a simple solution with the simple attribut before, but I didn't find anything. So I write a simple component, is very easy and I spent less time to develop myself than to search a simple solution.

              • 5. Re: Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It
                BhaskerChari Level 4

                Hi kiran,

                 

                Check for either click event or focusIn events...instead.

                 

                Actually mouseEnabled is not the event....it is the boolean property...you cannot specify the function in place of that.

                 

                Howver you can check out the PropmtTextInput component in the Flex lib tools. Check out the below link.

                 

                http://code.google.com/p/flexlib/wiki/ComponentList

                 

                Thanks,

                Bhasker

                • 6. Re: Flex 3:Clearing Default Value of TextInput when Mouse is clicked on It
                  Sepeleu Level 1

                  Hi Bhasker,

                   

                  Very good information !! I check out the source code and your solution is more clean than mine.

                   

                  Moreover , you're a solution to disable the copy/paste on TextInput ?

                   

                  thanks in advance.