Perfect!

This is how it works

Thank you very much!!

El jue., 18 jun. 2020 a las 13:49, Yishay Weiss (<[email protected]>)
escribió:

> Hi Raul,
>
> I noticed you’re now listening to the model bead and not the strand. I’m
> not sure now why that’s not working (we should check), but if the old way
> was working, you can simply replace:
>
> _model.addEventListener("selectionChanged", selectionChangedHandler);
>
> With
>
> (_strand as IEventDispatcher).addEventListener("selectionChanged",
> selectionChangedHandler);
>
> Thanks,
> Yishay
>
> From: Raúl Núñez<mailto:[email protected]>
> Sent: Thursday, June 18, 2020 2:29 PM
> To: [email protected]<mailto:[email protected]>
> Subject: Problem with standardization of the new Bead ComboBoxItemByField
>
> Hi:
>
> I commited a PR (869) with a new Bead for ComboBox: ComboBoxItemByField.
>
> Yishay said me that it could be very interesting to make some changes in
> order to use the bead in a more generic way.
>
> I've tried apply those changes but I haven't got it to work.
>
> My problem is selectionChangedHandler never launches. I have checked with
> another events as selectedItemChanged and selectedIndexChanged. Since the
> handler is never launched, the selectedValue variable is not updated.
>
>
> ComboBoxItemByField changes:
>
>
> ////////////////////////////////////////////////////////////////////////////////
> //
> //  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.core.IBead;
>   import org.apache.royale.core.IStrand;
>   import org.apache.royale.collections.CollectionUtils;
>   import org.apache.royale.events.Event;
>   import org.apache.royale.collections.ICollectionView;
>   import org.apache.royale.core.ISelectionModel;
>
>   /**
>      *  The _modelItemByField class is a specialty bead that can be used
> with
>      *  any _model control. This bead allows to select an item by field
>      *
>      *  @langversion 3.0
>      *  @playerversion Flash 10.2
>      *  @playerversion AIR 2.6
>      *  @productversion Royale 0.9.4
>      */
>
>   public class ComboBoxItemByField implements IBead{
>
>       protected var _model:ISelectionModel;
>       protected var _strand:IStrand;
>
>
>         /**
>          *  constructor.
>          *
>          *  @langversion 3.0
>          *  @playerversion Flash 10.2
>          *  @playerversion AIR 2.6
>          *  @productversion Royale 0.9.4
>          */
>       public function ComboBoxItemByField()
>         {
>         }
>
>         /**
>          *  @copy org.apache.royale.core.IBead#strand
>          *
>          *  @langversion 3.0
>          *  @playerversion Flash 10.2
>          *  @playerversion AIR 2.6
>          *  @productversion Royale 0.9.7
>          */
>         public function set strand(value:IStrand):void
>         {
>             _strand = value;
>             _model = _strand.getBeadByType(ISelectionModel) as
> ISelectionModel;
>             _model.addEventListener("selectionChanged"
> , selectionChangedHandler);
>             updateHost();
>         }
>
>         private var _valueField:String;
>         /**
>          *  The string that will be used for comparison field name
>          *
>          *  @langversion 3.0
>          *  @playerversion Flash 10.2
>          *  @playerversion AIR 2.6
>          *  @productversion Royale 0.9.4
>          */
>         public function get valueField():String
>         {
>             return _valueField;
>         }
>         public function set valueField(value:String):void
>         {
>             _valueField = value;
>             updateHost();
>         }
>
>         private var _selectedValue:*;
>
>         /**
>          *  Any kind of object to perform the comparison or select
>          *  the item with this value in the field.
>          *
>          *  @langversion 3.0
>          *  @playerversion Flash 10.2
>          *  @playerversion AIR 2.6
>          *  @productversion Royale 0.9.4
>          */
>         public function get selectedValue():*{
>             return _selectedValue;
>         }
>
>         public function set selectedValue(value:*):void{
>             _selectedValue = value;
>             updateHost();
>         }
>
>         /**
>          *  This bead allows update the selected item of the _model
> through the entered field
>          */
>         protected function updateHost():void
>         {
>             if(_model && valueField != "" && selectedValue != null){
>                 var aux:* = CollectionUtils
> .getItemByField(_model.dataProvider as ICollectionView
> ,valueField,selectedValue);
>                 if(aux == null){
>                     _model.selectedItem = null;
>                     _model.selectedIndex = -1;
>                 } else if (aux!==_model.selectedItem){
>                     _model.selectedItem = aux;
>                 }
>             }
>         }
>
>         /**
>          *  Select the right item for the _model.
>          *
>          *  @param event
>          */
>         protected function selectionChangedHandler(event:Event):void{
>             if(valueField != "" && _model){
>                 var selectedItem:Object = _model.selectedItem;
>                 if(selectedItem != null
>  && selectedValue !== selectedItem[valueField])
>                     selectedValue = selectedItem[valueField];
>             }
>         }
>
>   }
> }
>
>
> Componente example:
>
>  <j:ComboBox percentWidth="90" localId="comboCenter"
> labelField="displaytext"
> dateprovider="{centers}">
>                     <j:beads>
>                         <j:ComboBoxItemByField valueField="code" localId=
> "comboCenterItemByField" />
>                     </j:beads>
>                 </j:ComboBox>
>
> Thanks!!
>
>

Reply via email to