1 Reply Latest reply on Sep 7, 2007 9:33 AM by pzh19z

    Autofill ComboBox

    pzh19z Level 1
      I'm trying to extend the ComboBox control to allow users to type into the textInput and it will automatically find and fill out the rest of the selection from the listData. I can actually get it to select and autofill the textInput, the problem I'm having is that after it finds the first match it doesn't allow for much else.

      I need to be able to get the cursor position and select (highlight) the remain part of the phrase that was autofilled into the textInput area. I'm pretty sure I need to use the UITextField class, but have no idea how to do this with the ComboBox control.

      If someone knows how to do anything like this I'd appreciate the help.

      Here is the code to autofill the ComboBox with an item from the listData;

      // Capture the change event and attempt to auto fill the combobox from the select list.
      protected function changeEvent(event:Event):void
      {
      if (this.editable)
      {
      this.textInput.parent
      for (var x:Number=0; x<this.dataProvider.length; x++)
      {
      // Find an item in the list that matches the text you have entered.
      if (this.dataProvider[x][labelField].toString().toUpperCase().search(new RegExp("^"+this.text.toUpperCase()))!=-1) {
      this.text = this.dataProvider[x][labelField].toString();
      x=this.dataProvider.length;
      break;
      }
      }
      }
      }
        • 1. Re: Autofill ComboBox
          pzh19z Level 1
          I'm so close I can taste it. I however can't get the setSelection to work correctly. I believe the issue now is 'order of events'. Perhaps the change event handler in the ComboBox/TextInput is doing something after I do my stuff.

          if (this.editable)
          {
          var i:Number = 0;
          var y:Number = 0;

          for (var x:Number=0; x<this.dataProvider.length; x++)
          {
          // Find an item in the list that matches the text you have entered.
          if (this.text.length>0)
          {
          if (this.dataProvider[x][labelField].toString().toLowerCase().search(new RegExp("^("+this.text.toLowerCase()+")+?"))!=-1)
          {
          i = UITextField(TextInput(this.textInput).mx_internal::getTextField()).caretIndex;
          this.text = this.dataProvider[x][labelField].toString();
          y = this.text.length;
          UITextField(TextInput(this.textInput).mx_internal::getTextField()).setSelection(i+1,y);
          x=this.dataProvider.length;
          break;
          }
          }
          }