Hi Carlos,

I was able to replicate the issue on TDJ apply the fix and saw the issue
goes away.
BUT I had to clean everything and rebuild everything (I even put a console
log to be sure that I was testing updated version).
I thought that was normal.

Thank you for point me out about the remove listener.

Here the full source code updated file:

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.royale.jewel.beads.controls.combobox
{
import org.apache.royale.events.Event;
import org.apache.royale.jewel.beads.controls.combobox.IComboBoxView;
import org.apache.royale.jewel.beads.controls.textinput.SearchFilterForList;
import org.apache.royale.jewel.beads.views.ComboBoxView;
import org.apache.royale.jewel.supportClasses.textinput.TextInputBase;
    import org.apache.royale.jewel.List;
    import org.apache.royale.events.MouseEvent;

/**
*  The SearchFilter bead class is a specialty bead that can be used with
     *  a Jewel ComboBox to filter options as we type
*
*  @langversion 3.0
*  @playerversion Flash 10.2
*  @playerversion AIR 2.6
*  @productversion Royale 0.9.5
*/
public class SearchFilter extends SearchFilterForList
{
/**
*  constructor.
*
*  @langversion 3.0
*  @playerversion Flash 10.2
*  @playerversion AIR 2.6
*  @productversion Royale 0.9.5
*/
public function SearchFilter()
{
}

        public override function set list(value:List):void
        {
            super.list = value;
            COMPILE::JS
{
if (list != null)
           list.addEventListener(MouseEvent.CLICK, onListClick);
            }
        }

        private function onListClick(event:MouseEvent):void
        {
list.removeEventListener(MouseEvent.CLICK, onListClick);
            comboView.popUpVisible = false;
        }

private var comboView:IComboBoxView;

override protected function textInputKeyUpLogic(input:Object):void
{
if(!list) return;

// first remove a previous selection
if(list.selectedIndex != -1)
{
var tmp:String = input.text;
list.selectedItem = null;
input.text = tmp;
}

            if (!comboView.popUpVisible)
                comboView.popUpVisible = true;

// fill "list" with the internal list in the combobox popup
//list = comboView.popup.view.list;

applyFilter(comboView.textinput.text.toUpperCase());

ComboBoxView(comboView).autoResizeHandler(); //as we filter the popup list
will be smaller, and we want to reposition
}

override protected function selectItem(item:Object):void
{
// Select the item in the list if text is the same
// we do at the end to avoid multiple selection (if there's more than one
matches)
// in that case, select the first one in the list
// if(item != null)
// list.selectedItem = item;
}

override protected function onBeadsAdded(event:Event):void{
listenOnStrand('dismissPopUp', removeListListeners);
listenOnStrand('popUpOpened', popUpOpenedHandler);
listenOnStrand('popUpClosed', popUpClosedHandler);

comboView = event.target.view as IComboBoxView;
            if (comboView)
{
                var _textInput:TextInputBase = comboView.textinput as
TextInputBase;
                if (_textInput) {
COMPILE::JS
{
                    _textInput.element.addEventListener('focus',
onInputFocus);
                    }
            }
            }
}

override protected function onInputFocus(event:Event):void{
            if (!comboView.popUpVisible)
                comboView.popUpVisible = true;
}

protected function popUpOpenedHandler():void {
// fill "list" with the internal list in the combobox popup
list = comboView.popup.view.list;
}

protected function popUpClosedHandler():void {
list = null;
}
}
}

Carlos Rovira <carlosrov...@apache.org> escreveu no dia domingo, 18/10/2020
à(s) 18:04:

> Hi Hugo,
>
> when I tried that code I had to add the imports too.
> Anyway I tried again, and I'm getting the same fail in the TDJ SearchFilter
> example
> Are you getting the same?
> Also I think you'll need to remove the listener when the popup closes,
> since the list is recreated again and a new listener will be attached
> If you don't remove the listeners you left the list hanging and can't be
> garbage collected.
> thanks
>
> El dom., 18 oct. 2020 a las 18:02, Hugo Ferreira (<hferreira...@gmail.com
> >)
> escribió:
>
> > Hi Carlos,
> >
> > I was able to compile the Royale SDK with ant.
> > Built the TDJ and replicate the exactly issue that you mention before.
> > Applied a fix that keeps my original fix without the issue that you
> mention
> > but this time directly from the compiled Royale SDK + TDJ.
> >
> > So, the new code is 2 new imports:
> >     import org.apache.royale.jewel.List;
> >     import org.apache.royale.events.MouseEvent;
> >
> > And this:
> > public override function set list(value:List):void
> >         {
> >             super.list = value;
> >             COMPILE::JS
> > {
> > if (list != null)
> >            list.addEventListener(MouseEvent.CLICK, onListClick);
> >             }
> >         }
> >
> > private function onListClick(event:MouseEvent):void
> >         {
> >             comboView.popUpVisible = false;
> >         }
> >
> > What do you think ?
> >
> > Carlos Rovira <carlosrov...@apache.org> escreveu no dia quinta,
> 15/10/2020
> > à(s) 09:13:
> >
> > > Ok Hugo,
> > >
> > > many thanks :)
> > >
> > > El jue., 15 oct. 2020 a las 1:50, Hugo Ferreira (<
> hferreira...@gmail.com
> > >)
> > > escribió:
> > >
> > > > Hi Carlos,
> > > >
> > > > OK, let me try :)
> > > >
> > > > Carlos Rovira <carlosrov...@apache.org> escreveu no dia quarta,
> > > 14/10/2020
> > > > à(s) 08:29:
> > > >
> > > > > Hi Hugo,
> > > > >
> > > > > I'm trying that snippet in jewel with TDJ and as I start to
> interact
> > > with
> > > > > the CMB I get this:
> > > > >
> > > > > SearchFilter.as:123 Uncaught TypeError: Cannot read property
> > > > > 'addEventListener' of null
> > > > >     at
> > > > >
> > org.apache.royale.jewel.beads.controls.combobox.SearchFilter.set__list
> > > > > (SearchFilter.as:123)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.royale.jewel.beads.controls.combobox.SearchFilter.popUpClosedHandler
> > > > > (SearchFilter.as:115)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.royale.jewel.ComboBox.org.apache.royale.events.EventDispatcher.fireListeners
> > > > > (EventDispatcher.as:131)
> > > > >     at Function.goog.events.EventTarget.dispatchEventInternal_
> > > > > (eventtarget.js:381)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.royale.jewel.ComboBox.org.apache.royale.events.EventDispatcher.dispatchEvent
> > > > > (EventDispatcher.as:108)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.royale.jewel.ComboBox.org.apache.royale.core.ElementWrapper.dispatchEvent
> > > > > (ElementWrapper.js:229)
> > > > >     at Object.org.apache.royale.utils.sendStrandEvent
> > > > > (sendStrandEvent.js:28)
> > > > >     at
> > > org.apache.royale.jewel.beads.views.ComboBoxView.set__popUpVisible
> > > > > (ComboBoxView.as:232)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.royale.jewel.beads.controls.combobox.SearchFilter.org_apache_royale_jewel_beads_controls_combobox_SearchFilter_onListClick
> > > > > (SearchFilter.as:129)
> > > > >     at Function.goog.events.fireListener [as googFireListener]
> > > > > (events.js:744)
> > > > >
> > > > > I think you need to solve the way you are trying. You can
> monkeypatch
> > > the
> > > > > code, but doing that will be very difficult to do this kind of
> fixes.
> > > > > The best way is:
> > > > >
> > > > > 1.- have the source code building in your local (with maven and
> ant,
> > > for
> > > > > this I shared other times this script I use on Mac, that you can
> > adapt
> > > > for
> > > > > you [1])
> > > > > 2.- As you have the 3 repos working on your side you can change any
> > > > library
> > > > > and then do in the lib root folder : "mvn clean install
> > > > -Poption-with-swf"
> > > > > and then "ant" to build with both and check all is fine.
> > > > > 3.- Then you can use a test project like TDJ or any other to try
> your
> > > > > changes. For example if you are using maven you don't need to sync
> > the
> > > > > library since you get directly in you local repo and the test
> project
> > > > will
> > > > > use it in the next compilation with your changes.
> > > > >
> > > > > Thanks for trying to fix it and I'll wait for your thoughts and see
> > if
> > > > you
> > > > > can go further :)
> > > > >
> > > > > [1]
> > > >
> https://gist.github.com/carlosrovira/200753108de263fa43e80d3228213509
> > > > >
> > > > >
> > > > > El mié., 14 oct. 2020 a las 0:57, Hugo Ferreira (<
> > > hferreira...@gmail.com
> > > > >)
> > > > > escribió:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > As mention previous, I found a bug on ComboBox + SearchFilter
> bead:
> > > > > > https://github.com/apache/royale-asjs/issues/917
> > > > > > This bug happens easly on my application because I saw with a
> > > ComboBox
> > > > > with
> > > > > > many similar items but it also happens on Tour de Jewel (more
> > > difficult
> > > > > to
> > > > > > reproduce because all the items are different)
> > > > > >
> > > > > > After I bring the SearchFilter bead to my project, I found a fix
> or
> > > > > > workaround to this bug.
> > > > > > I confirm that the end result works well, however I would like to
> > > know
> > > > > what
> > > > > > do you think about this fix ?
> > > > > >
> > > > > > On SearchFilter.as, I added this on my side:
> > > > > > public override function set list(value:List):void
> > > > > > {
> > > > > > super.list = value;
> > > > > > COMPILE::JS
> > > > > > {
> > > > > > list.addEventListener(MouseEvent.CLICK, onListClick);
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > private function onListClick(event:MouseEvent):void
> > > > > > {
> > > > > > comboView.popUpVisible = false;
> > > > > > }
> > > > > >
> > > > > > If is OK, I can commit it.
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Carlos Rovira
> > > > > Apache Member & Apache Royale PMC
> > > > > *Apache Software Foundation*
> > > > > http://about.me/carlosrovira
> > > > >
> > > >
> > >
> > >
> > > --
> > > Carlos Rovira
> > > Apache Member & Apache Royale PMC
> > > *Apache Software Foundation*
> > > http://about.me/carlosrovira
> > >
> >
>
>
> --
> Carlos Rovira
> Apache Member & Apache Royale PMC
> *Apache Software Foundation*
> http://about.me/carlosrovira
>

Reply via email to