0 Replies Latest reply on Sep 10, 2007 8:04 AM by pzh19z

    Validating ComboBox text to it's dropdown list

    pzh19z Level 1
      I need help creating a validator that binds to the TextInput in the ComboBox and the dataProvider.

      I've extended the ComboBox to autofill the text as the user types. I however want to enforce that the user did actually select a valid entry (one that exists in the dropdown box). I've done this so that the user does not need to manually select an item or keep pressing the first letter of their selection until the correct selection shows up.

      I however can't get the validator to work correctly. Normally you can bind a validator to a field and an ArrayCollection, so that when you change a field it checks the ArrayCollection. Since I'm extending the ComboBox the ArrayCollection is provided as the dataProvider. When I try to bind the TextInput field to the dataProvider it says there is no field with a given name within the dataProvider.

      This is the error I receive;
      "Error: Unknown Property: 'make'..."

      Now I know 'make' is a property within the ArrayCollection that I provided to the dataProvider. I can also run in debug mode and look at the variables and see the ArrayCollection and its properties. Here is the Array I sent to the ArrayCollection;

      [Bindable]
      private var aMake:Array = new Array(
      {make:"Ford"},
      {make:"Chevy"},
      {make:"Pontiac"},
      {make:"Fot2"});

      Here is the actual validation code that gets executed on the ComboBox focusOutHandler.

      validator.source = this.dataProvider;
      validator.property = this.labelField;
      validator.required = true;
      validator.listener = this.textInput;
      validator.trigger = this.textInput;
      validatorEvent = validator.validate();
      if (validatorEvent.type == ValidationResultEvent.INVALID)
      {
      _bIsValid = false
      } else {
      _bIsValid = true;
      }