4 Replies Latest reply on Aug 6, 2008 8:48 AM by alice_data

    Problem with Rendering Combo Box Values

    alice_data Level 1
      Hi,

      I have a very newbie question here regarding how to select the values in the combo box values and load it into an external database through HTTPService.

      Below is the snippet of the combo box:
      <mx:Script>
      <![CDATA[
      [Bindable]
      public var classification: Array = [ {label:"Physician", data:1},
      {label:"Treatment Planner", data:2}, {label:"Admin", data:3} ];

      [Bindable]
      public var selectedItem:Object;

      <mx:FormItem label="Classification:">
      <mx:ComboBox dataProvider="{classification}" width="150"
      close="selectedItem=ComboBox(event.target).selectedItem"/>
      </mx:FormItem>
      ]]>
      </mx:Script>
      <mx:HTTPService id="srv" url=" http://localhost/test_flex.php" method="POST">
      <mx:request>
      <first_name>{first_name.text}</first_name>
      <last_name>{last_name.text}</last_name>
      <classification>{classification.selectedItem.label}</classification>
      </mx:request>
      </mx:HTTPService>

      This brings me the following error:
      Data binding will not be able to detect assignments to "classification".

      Could anyone please tell me what I might have to put here?
      Thanks in advance.

      Alice
        • 1. Re: Problem with Rendering Combo Box Values
          Gregory Lafrance Level 6
          1) Use ArrayCollection and [Bindable].

          public var classification: Array = [ {label:"Physician", data:1},
          {label:"Treatment Planner", data:2}, {label:"Admin", data:3} ];

          [Bindable]
          public var myAC:ArrayCollection = new ArrayCollection(classification);

          2) <mx:ComboBox id="cmb" dataProvider="{myAC}" width="150"
          close="selectedItem=cmb.selectedItem"/>
          3) <classification>{cmb.selectedItem.label}</classification>
          • 2. Re: Problem with Rendering Combo Box Values
            alice_data Level 1
            Hi,

            Looks like I am now getting rid of the error after the corrections, but I am not getting the right values into the database. As a matter of fact, every single value I have been trying to enter turned out to be an empty string.

            I am suspecting that this probably is because of other errors I have been having. Here is the code:

            Is there anything wrong that I have other than the errors I have been having issues with? Or, is it still with the same error?

            Alice
            • 3. Re: Problem with Rendering Combo Box Values
              cheftimo Level 2
              Alice, I have only looked at this very quickly, so I'm not completely sure - but try passing the first and last name parameters in your <mx:request> without the '.text', like this:
              {first_name}
              {last_name}
              • 4. Re: Problem with Rendering Combo Box Values
                alice_data Level 1
                Hello,

                Just as I was debugging as you were probably reading this, I had chunked down my code to only this segment:

                <?xml version="1.0" ?>
                <!-- Simple example to demonstrate the States class. -->
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="srv.send()">
                <mx:Script>
                <![CDATA[
                import mx.controls.dataGridClasses.DataGridColumn;
                import mx.controls.Image;
                import mx.events.ItemClickEvent;
                import mx.controls.Alert;
                import flash.net.navigateToURL;
                import flash.net.URLRequest;
                import flash.net.URLVariables;
                import mx.collections.*;
                import mx.collections.ArrayCollection;

                [Bindable]
                public var classification: Array = [ {label:"Test 1", data:1},
                {label:"Test 2", data:2}, {label:"Test 3", data:3} ];
                [Bindable]
                public var myAC:ArrayCollection = new ArrayCollection(classification);
                private function send_data():void {
                srv.send();
                }
                ]]>
                </mx:Script>

                <mx:HTTPService id="srv" url=" http://www.test.com/test/test_flex.php" method="POST">
                <mx:request>
                <first_name>{first_name.text}</first_name>
                <last_name>{last_name.text}</last_name>
                <classification>{cmb.selectedItem.label}</classification>
                </mx:request>
                </mx:HTTPService>
                <!-- Define a Panel container that defines the login form.-->
                <mx:Panel title="Login" id="loginPanel"
                horizontalScrollPolicy="off" verticalScrollPolicy="off"
                paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

                <mx:Text width="100%" color="blue"
                text="Sign in to View or Create Your Records. Click the 'Need to Register?' link to register."/>

                <mx:Form id="loginForm" >
                <mx:FormItem label="First Name:">
                <mx:TextInput id="first_name" text="{first_name.text}"/>
                </mx:FormItem>
                <mx:FormItem label="Last Name:">
                <mx:TextInput id="last_name" text="{last_name.text}"/>
                </mx:FormItem>
                <mx:FormItem label="Classified Category:">
                <mx:ComboBox id="cmb" dataProvider="{myAC}" width="150"
                close="cmb.selectedItem"/>
                </mx:FormItem>
                <mx:LinkButton id="registerLink" label="Need to Register?"
                click="send_data();"/>
                </mx:Form>
                </mx:Panel>
                </mx:Application>

                The HTTPService here sends the code to record information to the database. It turns out that the First Name and Last Name were recorded in correctly, but the <classification>{cmb.selectedItem.label}</classification> records in only Test 3, which is in the else statement as I have specified in the PHP code.

                Are there other things I have missed in this portion? I have no longer got the binding error as I have in my 1st post, but the values are still not right.

                Thanks again.

                Alice