8 Replies Latest reply on Sep 8, 2009 6:51 PM by David_F57

    Clearing TextArea(textflow) content

    David_F57 Level 5

      Is there a simple way to remove the content of a textarea programatically, no matter what methods I have tried short of manually deleteing content, as soon as I load new text the old text reappears.

       

      thanks.

        • 1. Re: Clearing TextArea(textflow) content
          David_F57 Level 5

          I can't believe no-one has tried to clear a textflow,  the documentation claiming that text=null or content=null will replace the existing content is wrong!

           

          the dirty solution

          while (textFlow.numChildren > 0) textFlow.removeChildAt(0);

           

          I'm sure the design pattern purists can turn this line of code into 15 classes spread over 5 folders each containing 3 files of 4 lines of code. Just to make it more efficient.

          • 2. Re: Clearing TextArea(textflow) content
            CoreyRLucier Adobe Employee

            So with a trunk build this works just fine (clicking button correctly clears the TextArea instance). Can you modify accordingly so that it fails in a consistent manner to what you are seeing?

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application
                xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/halo">
               
                <s:layout>
                    <s:VerticalLayout/>
                </s:layout>
               
               <s:TextArea id="ta" text="lskdjflksfs sdf dsjflsk dfs"/>
               
                <s:Button click="ta.text=null;" />
            </s:Application>

            • 3. Re: Clearing TextArea(textflow) content
              David_F57 Level 5

              I built the sdk from svn last friday so its reasonably up to date. All that =null does is clear the display it does not clear the textflow or textarea or richedit "buffer". If you then add .text="hello again" that is all that will be displayed. But at any point causing the textflow to refresh is like getting a history of everything that was entered into the object.

               

               

              .textFlow = TextFlowUtil.importFromXML(myDoc);  if you do this it is appended to the "erased"  content and displayed along with the it.

               

               

              David

               

               

              [edit] using =null is very poor methodology there should be textFlow.clear() added to the tlf library.

              • 4. Re: Clearing TextArea(textflow) content
                CoreyRLucier Adobe Employee

                Well, this works for me too.  What might I be doing wrong. Using the Clear button, then setting the textFlow specifically using either of the import methods seems to work.

                 

                -C

                 

                <?xml version="1.0" encoding="utf-8"?>
                <s:Application
                    xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/halo">
                   
                    <s:layout>
                        <s:VerticalLayout/>
                    </s:layout>
                   
                    <fx:Script>
                        <![CDATA[
                            import spark.utils.TextFlowUtil;
                            private var newText:XML = <span>This is a test</span>;
                        ]]>
                    </fx:Script>
                   <s:TextArea id="ta" text="lskdjflksfs sdf dsjflsk dfs"/>
                   
                    <s:Button label="Clear" click="ta.text=null;" />
                    <s:Button label="From String" click="ta.textFlow = TextFlowUtil.importFromString('blah blah blah');"/>
                    <s:Button label="From XML" click="ta.textFlow = TextFlowUtil.importFromXML(newText);"/>
                </s:Application>

                • 5. Re: Clearing TextArea(textflow) content
                  David_F57 Level 5

                  I have attached a file which shows the =null failing. I have no answer to why it isn't working for me.

                  • 6. Re: Clearing TextArea(textflow) content
                    Carol L. Frampton Level 2

                    The problem is that TextFlowUtil.importFromXML(mnu_pizzas) is not working correctly.  The state from the previous import is not properly cleared so the pizza info is being appended to the breakfast info.  If you export the textFlow right after you create it you will see the problem.

                     

                    The workaround is to call

                    TextConverter.importToFlow(mnu_breakfast/mnu_pizzas, TextConverter.TEXT_LAYOUT_FORMAT);

                    for each import.


                    Thanks for the bug report.  We will see that it gets fixed.

                    • 7. Re: Clearing TextArea(textflow) content
                      David_F57 Level 5

                      I was starting to think that it was a bug, the interesting thing is that under the right circumstances the issue still remains with the TextConverter method. If I don't try to nullify the content first then TextConverter works fine everytime (I just wish I had thought about that a week ago when I was having problems with TextConverter). Anyway my quick and dirty fix can be removed now.

                       

                      Thanks

                      David

                      • 8. Re: Clearing TextArea(textflow) content
                        David_F57 Level 5

                        Hi Corey,

                         

                        Thanks for having a look at this, I probably should have put the sample up straight away, but I am sure that as a developer I'm supposed to avoid "documenting".

                         

                        David.