4 Replies Latest reply on Feb 2, 2010 6:52 AM by 00_Flex

    Passing the option value id vs. the option name. Option name should show in the drop down.

    00_Flex

      The complete flex source is uploaded to a file called source.txt. Using Flex as the front and and a .CFC as the back end. Using

      the remote object to call the cfc and populate the combo boxes. That is working fine. When the user hits the submit button after selecting

      the combo box values want to send the option id which should be the "ticket_source_id" column in the sql statement for the "sourceInput" combo box

      to send the id to the cfc. Right now when the user select "Phone" for example the source string "Phone" gets sent. Want to get the

      value id which would be "2" to be sent instead when this service is called "sourceDataService.goCreateTicket". Any help would be great.

       

      Thanks.

        • 1. Re: Passing the option value id vs. the option name. Option name should show in the drop down.
          archemedia Level 4

          Sorry, but I don't have time to go through all your code, but here's some help:

           

          What is the dataProvider of your comboBox? It should be an arrayCollection of objects coming from your service right?

           

          Something like

           

          [{id: 1, value: "Some Value"}, {id: 2, value: "Some other value"}]

           

          and then

           

          <mx:ComboBox id="myCB" dataProvider="{dp}" labelField="value"/>

           

          You can access the id at any time by:

           

          myCB.selectedItem.id;

           

          Does this help?

           

          Dany

          • 2. Re: Passing the option value id vs. the option name. Option name should show in the drop down.
            00_Flex Level 1

            Yes. Thank you for your quick response! Very helpful!

             

            New snippet of code attached with the changes you suggested.

             

            I still have one question. On this part:

             

            [Bindable]
            private var recievedSourceData:ArrayCollection = new ArrayCollection( [ {id: ? , value: ?   } ]     );

             

            where the "?" marks are see attached code "source2.txt" my ArrayCollection is being populating dynamically from

            the cfc query, so I am not hard coding the values in. The source data could be different for each instance of the

            application. Meaning there could be 10 values or 5 values in the drop down.

             

            I tried:

             

             

            [Bindable]
            private var recievedSourceData:ArrayCollection = new ArrayCollection( [ {id: TICKET_SOURCE_ID , value: TICKET_SOURCE_NAME   } ]);

             

            but got errors. Any more help would be greatly appreciated.

             

            Thanks!

            • 3. Re: Passing the option value id vs. the option name. Option name should show in the drop down.
              archemedia Level 4

              [Bindable]
              private var recievedSourceData:ArrayCollection = new ArrayCollection(); // Keep this empty

               

              private function getSource(returnedEvent:ResultEvent):void

              {
                       recievedSourceData = returnedEvent.result as ArrayCollection;
              }

               

              private function sendForm():void

              {

                       sourceDataService.goCreateTicket (sourceInput.selectedItem.TICKET_SOURCE_ID);
              }

               

              ...

               

              <mx:ComboBox dataProvider="{recievedSourceData}" labelField="TICKET_SOURCE_NAME" id="sourceInput">

               

               

               

               

              This looks right! The result property of your returnedEvent should be an arrayCollection of objects (doesn't matter how much). Each object has a TICKET_SOURCE_ID and  TICKET_SOURCE_NAME property. If you don't alter the names of these properties, then your labelField of the comboBox should be set to TICKET_SOURCE_NAME, so that it matches the property name!

               

              Dany