Loading ...
Sorry, an error occurred while loading the content.

Re: Getting the selectedItem in the dropdown list for AutoCompleteManager

Expand Messages
  • teo.kenneth
    Nice workaround. Appreciate it alot!! One problem i have is that i will not be able to pick out the selected object if i used the keyboard up/down arrows.. The
    Message 1 of 8 , Dec 31, 2008
    View Source
    • 0 Attachment
      Nice workaround. Appreciate it alot!!

      One problem i have is that i will not be able to pick out the selected
      object if i used the keyboard up/down arrows.. The reason this is a
      problem for me is that i am using this AutoCompleteManager(inside an
      itemrenderer component) for data entry onto a datagrid; everything is
      preferably done with the keyboard. I'll live with this nice workaround
      as i can now achieve the desired behaviour.

      Will be nice to have the selectedIndex or selectedItem just as we have
      it on the mx:ComboBox control

      Happy New Year

      Kenneth Teo
      kennethteo.com


      --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@...> wrote:
      >
      > Glad you're finding AutoCompleteManager useful. If your primary
      > concern is getting the object that is selected, you can get to it
      > currently using the following (admittedly roundabout) methods:
      >
      > <yahoo:AutoCompleteManager
      >
      change="trace(AutoCompleteManager(event.currentTarget).dataProvider.getItemAt(event.rowIndex))"
      > />
      >
      > This example would trace out the item that was just selected. I'm
      > looking into a way to make this more apparent. But for now that should
      > get you the data you need.
      >
      > Happy New Year!
      >
      > Alaric
      > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@> wrote:
      > >
      > > Hi,
      > >
      > > I've noticed that the dataprovider becomes the first item so i have
      > > tried adding event listeners to the change and close event. However,
      > > the behavior is not consistent.
      > >
      > > I was hoping for either of the following:
      > >
      > > 1) upon selecting the item in the dropdown, a bindable var of the
      > > autocompletemanager can be set. That way i can do something like this:
      > > var item:Object = autocompletemgr.selectedItem;
      > >
      > > 2) set the selecteditem on the change event.
      > >
      > >
      > >
      > > I really like this autocompletemanager. Will be great if the above can
      > > be done as i believe most of us do not just need the selectedLabel.
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
      > > >
      > > > There is a selectedItem as well as a selectedLabel. However,
      they may
      > > > not work as expected due to the nature of the AutoComplete--once an
      > > > item is chosen, the list is typically set to an empty
      dataprovider and
      > > > thus will not have a selectedItem. Let me know what you'd
      expect, and
      > > > I may be able to rework it to add that functionality.
      > > >
      > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
      wrote:
      > > > >
      > > > > Been looking for a way to get the selectedItem in the dropdown
      list
      > > > > after making a selection. Has anyone done it yet?
      > > > >
      > > >
      > >
      >
    • Mat
      I have the same problem with the keyboard up/down, I get the following error message: RangeError: Index -1 specified is out of bounds. ... selected ... is
      Message 2 of 8 , Jan 5, 2009
      View Source
      • 0 Attachment
        I have the same problem with the keyboard up/down, I get the
        following error message:

        RangeError: Index '-1' specified is out of bounds.

        --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@...>
        wrote:
        >
        > Nice workaround. Appreciate it alot!!
        >
        > One problem i have is that i will not be able to pick out the
        selected
        > object if i used the keyboard up/down arrows.. The reason this is a
        > problem for me is that i am using this AutoCompleteManager(inside an
        > itemrenderer component) for data entry onto a datagrid; everything
        is
        > preferably done with the keyboard. I'll live with this nice
        workaround
        > as i can now achieve the desired behaviour.
        >
        > Will be nice to have the selectedIndex or selectedItem just as we
        have
        > it on the mx:ComboBox control
        >
        > Happy New Year
        >
        > Kenneth Teo
        > kennethteo.com
        >
        >
        > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
        > >
        > > Glad you're finding AutoCompleteManager useful. If your primary
        > > concern is getting the object that is selected, you can get to it
        > > currently using the following (admittedly roundabout) methods:
        > >
        > > <yahoo:AutoCompleteManager
        > >
        > change="trace(AutoCompleteManager
        (event.currentTarget).dataProvider.getItemAt(event.rowIndex))"
        > > />
        > >
        > > This example would trace out the item that was just selected. I'm
        > > looking into a way to make this more apparent. But for now that
        should
        > > get you the data you need.
        > >
        > > Happy New Year!
        > >
        > > Alaric
        > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
        wrote:
        > > >
        > > > Hi,
        > > >
        > > > I've noticed that the dataprovider becomes the first item so i
        have
        > > > tried adding event listeners to the change and close event.
        However,
        > > > the behavior is not consistent.
        > > >
        > > > I was hoping for either of the following:
        > > >
        > > > 1) upon selecting the item in the dropdown, a bindable var of
        the
        > > > autocompletemanager can be set. That way i can do something
        like this:
        > > > var item:Object = autocompletemgr.selectedItem;
        > > >
        > > > 2) set the selecteditem on the change event.
        > > >
        > > >
        > > >
        > > > I really like this autocompletemanager. Will be great if the
        above can
        > > > be done as i believe most of us do not just need the
        selectedLabel.
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
        > > > >
        > > > > There is a selectedItem as well as a selectedLabel. However,
        > they may
        > > > > not work as expected due to the nature of the AutoComplete--
        once an
        > > > > item is chosen, the list is typically set to an empty
        > dataprovider and
        > > > > thus will not have a selectedItem. Let me know what you'd
        > expect, and
        > > > > I may be able to rework it to add that functionality.
        > > > >
        > > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
        > wrote:
        > > > > >
        > > > > > Been looking for a way to get the selectedItem in the
        dropdown
        > list
        > > > > > after making a selection. Has anyone done it yet?
        > > > > >
        > > > >
        > > >
        > >
        >
      • teo.kenneth
        Did another workaround for this problem. I made a component (for my case a datagrid itemrenderer) that is a subclass of a textinput. By using a combination of
        Message 3 of 8 , Jan 11, 2009
        View Source
        • 0 Attachment
          Did another workaround for this problem.

          I made a component (for my case a datagrid itemrenderer) that is a
          subclass of a textinput.

          By using a combination of open, close, change event.

          <mx:TextInput.....>
          <yahoo:AutoCompleteManager
          id="autoCompleteMgr"
          target="{this}"

          dataProvider="{Cairngornmodellocator.getInstance().dataproviderforastraa\
          utocompletemanager}"
          labelField="memberName"
          maxRowCount="3"

          minCharsForCompletion="2"

          filterFunction="memberFilterFunction"

          change="setSelection(event)"

          close="setSelectedItem(event)"

          open="resetKeyboardSelection(event)"

          <mx:Script>
          <![CDATA[
          private var keyboardSelection:int = -1;
          private var getFromKeyboardSelection:Boolean = false;
          private function setSelection(event:ListEvent):void
          {

          trace (event.rowIndex);
          //differentiate between a keyboard selection or mouse selection
          try {
          selectedItem =
          AutoCompleteManager(event.currentTarget).dataProvider.getItemAt(event.ro\
          wIndex);
          getFromKeyboardSelection = false;
          }
          catch (err:Error) {
          getFromKeyboardSelection = true;
          trace(err);
          }
          }
          private function setSelectedItem(event:Event):void
          {
          try {
          //if selection was made with keyboard
          if (getFromKeyboardSelection)
          selectedItem =
          AutoCompleteManager(event.currentTarget).dataProvider.getItemAt(keyboard\
          Selection);
          }
          catch (err:Error) {
          trace(err);
          }
          this.removeEventListener(KeyboardEvent.KEY_UP, setKeyboardSelection
          );

          if (selectedItem)
          {
          var myListData:DataGridListData = DataGridListData(listData);
          var row:int=myListData.rowIndex +myDG.verticalScrollPosition;
          var col:int=myListData.columnIndex+1;


          Cairngormmodellocator.getInstance().someArrayCol.getItemAt(row)['somefie\
          ld'] = selectedItem.somefield;
          }
          }
          private function resetKeyboardSelection(event:Event):void
          {
          keyboardSelection = -1;
          this.addEventListener(KeyboardEvent.KEY_UP, setKeyboardSelection );
          }
          private function setKeyboardSelection(event:KeyboardEvent):void
          {
          if (event.keyCode == Keyboard.UP)
          {
          if (keyboardSelection > 0)
          keyboardSelection--;
          }
          else if (event.keyCode == Keyboard.DOWN)
          keyboardSelection++;
          }
          ]]>
          </mx:Script>
          </mx:TextInput>

          --- In ydn-flash@yahoogroups.com, "Mat" <molsengolden@...> wrote:
          >
          > I have the same problem with the keyboard up/down, I get the
          > following error message:
          >
          > RangeError: Index '-1' specified is out of bounds.
          >
          > --- In ydn-flash@yahoogroups.com, "teo.kenneth" kenneth.teo@
          > wrote:
          > >
          > > Nice workaround. Appreciate it alot!!
          > >
          > > One problem i have is that i will not be able to pick out the
          > selected
          > > object if i used the keyboard up/down arrows.. The reason this is a
          > > problem for me is that i am using this AutoCompleteManager(inside an
          > > itemrenderer component) for data entry onto a datagrid; everything
          > is
          > > preferably done with the keyboard. I'll live with this nice
          > workaround
          > > as i can now achieve the desired behaviour.
          > >
          > > Will be nice to have the selectedIndex or selectedItem just as we
          > have
          > > it on the mx:ComboBox control
          > >
          > > Happy New Year
          > >
          > > Kenneth Teo
          > > kennethteo.com
          > >
          > >
          > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
          > > >
          > > > Glad you're finding AutoCompleteManager useful. If your primary
          > > > concern is getting the object that is selected, you can get to it
          > > > currently using the following (admittedly roundabout) methods:
          > > >
          > > > <yahoo:AutoCompleteManager
          > > >
          > > change="trace(AutoCompleteManager
          > (event.currentTarget).dataProvider.getItemAt(event.rowIndex))"
          > > > />
          > > >
          > > > This example would trace out the item that was just selected. I'm
          > > > looking into a way to make this more apparent. But for now that
          > should
          > > > get you the data you need.
          > > >
          > > > Happy New Year!
          > > >
          > > > Alaric
          > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
          > wrote:
          > > > >
          > > > > Hi,
          > > > >
          > > > > I've noticed that the dataprovider becomes the first item so i
          > have
          > > > > tried adding event listeners to the change and close event.
          > However,
          > > > > the behavior is not consistent.
          > > > >
          > > > > I was hoping for either of the following:
          > > > >
          > > > > 1) upon selecting the item in the dropdown, a bindable var of
          > the
          > > > > autocompletemanager can be set. That way i can do something
          > like this:
          > > > > var item:Object = autocompletemgr.selectedItem;
          > > > >
          > > > > 2) set the selecteditem on the change event.
          > > > >
          > > > >
          > > > >
          > > > > I really like this autocompletemanager. Will be great if the
          > above can
          > > > > be done as i believe most of us do not just need the
          > selectedLabel.
          > > > >
          > > > >
          > > > >
          > > > >
          > > > >
          > > > >
          > > > >
          > > > >
          > > > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
          > > > > >
          > > > > > There is a selectedItem as well as a selectedLabel. However,
          > > they may
          > > > > > not work as expected due to the nature of the AutoComplete--
          > once an
          > > > > > item is chosen, the list is typically set to an empty
          > > dataprovider and
          > > > > > thus will not have a selectedItem. Let me know what you'd
          > > expect, and
          > > > > > I may be able to rework it to add that functionality.
          > > > > >
          > > > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
          > > wrote:
          > > > > > >
          > > > > > > Been looking for a way to get the selectedItem in the
          > dropdown
          > > list
          > > > > > > after making a selection. Has anyone done it yet?
          > > > > > >
          > > > > >
          > > > >
          > > >
          > >
          >
        • alariccole
          That reference error was my bug, due to the ListEvent not having the proper rowIndex. Just wanted to let everyone know that this is fixed and about to be
          Message 4 of 8 , Mar 11, 2009
          View Source
          • 0 Attachment
            That reference error was my bug, due to the ListEvent not having the proper rowIndex. Just wanted to let everyone know that this is fixed and about to be released in version 1.4.

            I still recommend the change event for getting the selected item, as this is the only sure-fire way when we're dealing with multiple autocompletes--remember that AutoCompleteManager manages any number of these, so it can't have a selectedItem per se. AutoCompleteManager is being used for a set of tools for Y!OS, and this is the way we do it. Keyboard access should work just as well, since the change event is fired when the dropdown is changed via the keyboard.

            Alaric

            --- In ydn-flash@yahoogroups.com, "Mat" <molsengolden@...> wrote:
            >
            > I have the same problem with the keyboard up/down, I get the
            > following error message:
            >
            > RangeError: Index '-1' specified is out of bounds.
            >
            > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
            > wrote:
            > >
            > > Nice workaround. Appreciate it alot!!
            > >
            > > One problem i have is that i will not be able to pick out the
            > selected
            > > object if i used the keyboard up/down arrows.. The reason this is a
            > > problem for me is that i am using this AutoCompleteManager(inside an
            > > itemrenderer component) for data entry onto a datagrid; everything
            > is
            > > preferably done with the keyboard. I'll live with this nice
            > workaround
            > > as i can now achieve the desired behaviour.
            > >
            > > Will be nice to have the selectedIndex or selectedItem just as we
            > have
            > > it on the mx:ComboBox control
            > >
            > > Happy New Year
            > >
            > > Kenneth Teo
            > > kennethteo.com
            > >
            > >
            > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
            > > >
            > > > Glad you're finding AutoCompleteManager useful. If your primary
            > > > concern is getting the object that is selected, you can get to it
            > > > currently using the following (admittedly roundabout) methods:
            > > >
            > > > <yahoo:AutoCompleteManager
            > > >
            > > change="trace(AutoCompleteManager
            > (event.currentTarget).dataProvider.getItemAt(event.rowIndex))"
            > > > />
            > > >
            > > > This example would trace out the item that was just selected. I'm
            > > > looking into a way to make this more apparent. But for now that
            > should
            > > > get you the data you need.
            > > >
            > > > Happy New Year!
            > > >
            > > > Alaric
            > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
            > wrote:
            > > > >
            > > > > Hi,
            > > > >
            > > > > I've noticed that the dataprovider becomes the first item so i
            > have
            > > > > tried adding event listeners to the change and close event.
            > However,
            > > > > the behavior is not consistent.
            > > > >
            > > > > I was hoping for either of the following:
            > > > >
            > > > > 1) upon selecting the item in the dropdown, a bindable var of
            > the
            > > > > autocompletemanager can be set. That way i can do something
            > like this:
            > > > > var item:Object = autocompletemgr.selectedItem;
            > > > >
            > > > > 2) set the selecteditem on the change event.
            > > > >
            > > > >
            > > > >
            > > > > I really like this autocompletemanager. Will be great if the
            > above can
            > > > > be done as i believe most of us do not just need the
            > selectedLabel.
            > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > > > > --- In ydn-flash@yahoogroups.com, "alariccole" <alaric@> wrote:
            > > > > >
            > > > > > There is a selectedItem as well as a selectedLabel. However,
            > > they may
            > > > > > not work as expected due to the nature of the AutoComplete--
            > once an
            > > > > > item is chosen, the list is typically set to an empty
            > > dataprovider and
            > > > > > thus will not have a selectedItem. Let me know what you'd
            > > expect, and
            > > > > > I may be able to rework it to add that functionality.
            > > > > >
            > > > > > --- In ydn-flash@yahoogroups.com, "teo.kenneth" <kenneth.teo@>
            > > wrote:
            > > > > > >
            > > > > > > Been looking for a way to get the selectedItem in the
            > dropdown
            > > list
            > > > > > > after making a selection. Has anyone done it yet?
            > > > > > >
            > > > > >
            > > > >
            > > >
            > >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.