3 Replies Latest reply on Nov 25, 2009 1:50 AM by ramace

    Facing problem in extending ComboBox

    ramace

      Hi,

       

      I am creating a autocomplete box, which fetches the required results from a server.

      So, what I am doing is extending a ComboBox and overriding the commit properties function to do a request to server and update the dataProvider.

       

      The code snippet: (editable property of ComboBox is set to true)

       

              override protected function commitProperties():void
              {
                  prompt = text;
                 
                  if (promptTextChanged) // becomes true whenever text in combobox is edited
                    {
                       //must do this otherwise the text get reset
                      textInput.setSelection(textInput.selectionEndIndex, textInput.selectionEndIndex);
                      promptTextChanged = false;
                     
                      // Dispatch typed text on min characters required to suggest 
                      if (prompt.length >= minCharsRequiredForSuggest) // assume minCharsRequiredForSuggest = 3
                      {

                          // this is done to fetch the data.
                          dispatchEvent(new AutoCompleteComboBoxEvent(AutoCompleteComboBoxEvent.FETCH_DATA, {'typedText':prompt}));
                      }
                  }
                 
                  //call it at the end or we get weird behavior, where we can't type more than
                  //one letter
                  super.commitProperties();
              }

       

      Now, coming to the problem as soon as I type 3 charecters, dispatchEvent is called, but ComboBox internally calls the close() function and whatever is typed in the ComboBox gets selected, so now if I type the 4th charecter, whatever I typed previously gets deleted.

       

      I tried overriding the close() function of ComboBox, but that didn't solve the issue.

       

      Please let me know if I can explain my problem better.

       

      Thanks in advance.