Three ComboBoxes Dependent on Each Other - Please Help

I am trying to figure out how to make the data displayed in three ComboBoxes dependent on each other while not hard-coding business rules in "if" constructs, but instead use an ArrayCollection of invalid combinations.
After compiling the following code and launching, the "$100.00" item in the Tariff ComboBox will be grayed out and inactive
because its "valid" field is "false".
QUESTION: what should be added to this application to support the following use cases of the ComboBoxes:
1) If the user selects clothes and China in the Product and Source ComboBoxes, the "valid" field for the "$100.00" item in the "tariff" ArrayCollection changes to "true", so the "$100.00" item is black and active. Also, the "valid" field for the "none" item in the "tariff" ArrayCollection changes to "false", so the "none" item is gray and inactive.
2) If after performing 1) above, the user selects Mexico Source ComboBox, the "valid" field for the "$100.00" item in the "tariff" ArrayCollection changes to "false", so the "$100.00" item is gray and inactive. Also, the "valid" field for the "none" item in the "tariff" ArrayCollection changes to "true", so the "none" item is black and active
I do not want to hard-code these business rules using if() constructs in ComboBox change handlers. Instead, I want to use the "invalid" ArrayCollection below to enforce whatever invalid combinations are in that AC. This will enable a flexible system.
I've been wracking my brain on this one so please help.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  creationComplete="init();">
  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.events.FlexEvent;
      /* The items in these ComboBoxes will be grayed out and inactive
         if their "valid" field is "false".
         After launching the application, open the "Tariff" ComboBox
         and notice the $100.00 item is grayed out and cannot be selected.
         QUESTION: what should be added to this application to support
                   the following use cases of the ComboBoxes:
         1) If the user selects clothes and China in the Product and
             Source ComboBoxes, the "valid" field for the "$100.00" item
             in the "tariff" ArrayCollection changes to "true", so the
             "$100.00" item is black and active. Also, the "valid" field
             for the "none" item in the "tariff" ArrayCollection changes
             to "false", so the "none" item is gray and inactive
         2) If after performing 1) above, the user selects Mexico Source
             ComboBox, the "valid" field for the "$100.00" item in the
             "tariff" ArrayCollection changes to "false", so the "$100.00"
             item is gray and inactive. Also, the "valid" field for the
             "none" item in the "tariff" ArrayCollection changes to "true",
             so the "none" item is black and active
         I do not want to hard-code these business rules using if() constructs
         in ComboBox change handlers. Instead, I want to use the "invalid"
         ArrayCollection below to enforce whatever invalid combinations
         are in that AC. This will enable a flexible system.
      [Bindable] private var product:ArrayCollection = new ArrayCollection([
        {label: "cars", valid: true},
        {label: "clothes", valid: true}
      [Bindable] private var source:ArrayCollection = new ArrayCollection([
        {label: "China", valid: true},
        {label: "Mexico", valid: true}
      [Bindable] private var tariff:ArrayCollection = new ArrayCollection([
        {label: "none", valid: true},
        {label: "$100.00", valid: false}
      [Bindable] private var invalid:ArrayCollection = new ArrayCollection([
        ["cars"],["China"],["$100.00"],
        ["clothes"],["China"],["none"],
        ["clothes"],["Mexico"],["$100.00"]
      [Bindable] private var currProduct:Object = new Object();
      [Bindable] private var currSource:Object = new Object();
      [Bindable] private var currTariff:Object = new Object();
      private function init():void{
        systemManager.addEventListener(FlexEvent.VALUE_COMMIT, sysMgrHandler, true);
      private function sysMgrHandler(evt:FlexEvent):void{
        if(evt.target is ComboBox){
          var tgt:ComboBox = evt.target as ComboBox;
          switch(tgt){
            case cbxOne:
              if(tgt.selectedItem.valid == false){
                tgt.selectedItem = currProduct;
              break;
            case cbxTwo:
              if(tgt.selectedItem.valid == false){
                tgt.selectedItem = currSource;
              break;
            case cbxThree:
              if(tgt.selectedItem.valid == false){
                tgt.selectedItem = currTariff;
              break;
    ]]>
  </mx:Script>
  <mx:Label text="Tariff Calculator"/>
  <mx:Canvas width="{hb.width}">
    <mx:Label text="Product:" x="{cbxOne.x}"/>
    <mx:Label text="Source:" x="{cbxTwo.x}"/>
    <mx:Label text="Tariff:" x="{cbxThree.x}"/>
  </mx:Canvas>
  <mx:HBox id="hb">
    <mx:ComboBox id="cbxOne" dataProvider="{product}" open="currProduct=cbxOne.selectedItem;">
      <mx:itemRenderer>
        <mx:Component>
          <mx:Label text="{data.label}" color="{uint(data.valid==true?0x000000:0xCCCCCC)}"/>         
        </mx:Component>
      </mx:itemRenderer>
    </mx:ComboBox>
    <mx:ComboBox id="cbxTwo" dataProvider="{source}" open="currSource=cbxTwo.selectedItem;">
      <mx:itemRenderer>
        <mx:Component>
          <mx:Label text="{data.label}" color="{uint(data.valid==true?0x000000:0xCCCCCC)}"/>         
        </mx:Component>
      </mx:itemRenderer>
    </mx:ComboBox>
    <mx:ComboBox id="cbxThree" dataProvider="{tariff}" open="currTariff=cbxThree.selectedItem;">
      <mx:itemRenderer>
        <mx:Component>
          <mx:Label text="{data.label}" color="{uint(data.valid==true?0x000000:0xCCCCCC)}"/>         
        </mx:Component>
      </mx:itemRenderer>
    </mx:ComboBox>
  </mx:HBox>
</mx:Application>

It seems like you may want another layer of indirection here. Not necessarily another class (that's probably needed, but orthogonal), but it seems awkward that your "valid/invalid" flags are sitting there directly in the combobox data provider ACs.The items themselves aren't really valid or invalid: it's whether they are selectable in the comboboxes based on the state of the entire application. Instead of storing plain Objects in those ACs, I'd suggest something like
class Validator {
  public var selectedSource:String;
  public var selectedProduct:String;
  public var selectedTarriff:String;
  public var invalid:ArrayList
  public function isValid(type:String,item:String):Boolean {
    // loop over invalid to determine whether this particular item is valid, given the
    // currernt combination of selected items
class ValidatedItem {
  public var name:String;
  public var type:String;
  public var validator:Validator;
  public function get valid():Boolean {
    return validator.isValid(type, name);
Then fill your combobox dataproviders with ValidatedItems instead of Objects. You'll need to instantiate the Validator once for the app and inject it into each item (a Dependency Injection infrastructure like Mate or SmartyPants can make this easier). You can use a Singleton instead if that's more your thing (I'm trying to de-Singleton my life).
I think that you'll need to wire some extra binding to Validator since otherwise ValidatedItem won't update the valid property when the selected items on Validator change, but that's straigthforward.
Is this the sort of approach you were thinking of?
Maciek Sakrejda
Truviso, Inc.
www.truviso.com
Truviso is hiring: http://www.truviso.com/company-careers.php?i=87

Similar Messages

  • Select boxes dependent on each other?

    Hi is there a way to use selectboxes / textfileds that depend on each other.
    select box 1. reads from database names
    select box 2. this one is filled when a chiose from box 1 is selected.
    (after a database question based on the result in box 1)
    inupttextfields 1 and 2 are filled after a new database request based on the choise in select box 2.
    pleased with different kind of answers. without javascripts adn also with use of
    javascripts. (Im not so used with javascripts)
    Plese give me a simple example and not just a link.
    thanks.

    Plese give me a simple example and not just a link.There is no simple example, because this is highly specific on your webpage implementation and database. search google for "javascript dynamic select box", or "javascript dynamic option lists". That should give you some examples.

  • I have two children both have ipods and my wife and i both have iphones. how do open up a seperate library for each device. please help i hate itunes at the moment

    We have four apple devices and one home cmputer how can i have a seprate itunes library for each device. please help!!!!!!!!!!!!!!!

    How to use multiple iPods, iPads, or iPhones with one computer

  • I have two apple id's because my hotmail account is no longer active. How can I delete the old one and use or update the new one?  Every time I try it won't allow me and now my iPad thinks there are two accounts and they are arguing with each other. Help!

    I have two apple id's because my hotmail account is no longer active. How can I delete the old one and use or update the new one?  Every time I try it won't allow me and now my iPad thinks there are two accounts and they are arguing with each other. Help!

    You can't merge accounts or copy content to a different account, so anything that you bought or downloaded via the old account is tied to that account - so any updates that those apps get you will only be able to download via that account. You can change which account is logged in on the iPad via Settings > Store

  • When syncing my iPhone the storage says OTHER what is other and how do you delete it or make it smaller  my 16g phone has 3G of other please help get rid of it

    iitWhen syncing my iPhone the storage says OTHER what is other and how do you delete it or make it smaller  my 16g phone has 3G of other please help get rid of it

    The following has some information that may help: http://osxdaily.com/2013/07/24/remove-other-data-storage-iphone-ipad/

  • I just got the iphone 4s and my text messages are showing as urgent to others,please help me fix this

    i just got the iphone 4s and my text messages are showing as urgent to others,please help me fix this

    As ckuan said, there's no way to mark messages as urgent from the phone. So, either your carrier is doing something and you'll need to contact them or it't something on the other end. Is it just one person who's seeing your texts as urgent? Or everyone?

  • HT4972 I cannot pair my new I pad 3 with my I phone 4, both are now running os 5.1.1, will pair with other Bluetooth but not each other. Help please

    I cannot pair my new iPad 3 with my iphone4, both are now running on os 5.1.1, please help with any suggestions you may have.  They are both pairing with other Bluetooth devices (including the wife's iPhone 3G on 4.2.1).  Thanks.

    Hi,
    I have purchased a wifi only I pad 3 in the hope I could thether using the 3G through my I phone 4.
    My I phone 4 and my iPad 3 cannot seem to find each other at all through Bluetooth yet
    Can find other devices ok no problems. I am wondering if it is an issue with os 5.1.1

  • HT1418 I am having trouble syncing my iphone5 with my contacts on my PC. I have over 350 contacts and it will only syncing 30 of them. What should I do to resolve this without having to manually load each contact please help

    I am having trouble syncing my iPhone5 with my PC computer. It is only syncing and transferring 50 contacts were as I have over 350 contacts. I have followed the step by step procedure with no luck. Does anyone have any ideas how to resolve otherwise I will have manually load each number individually please help.

    Any errors?
    What application are the contacts stored in?

  • My Ical is all screwed up now that I've upgraded my Mac Desktop.  There are no borders with the days of the week and it's all running into each other.  Help Pleeease!!  I have a busy schedule and this is so confusing. How do I get my old Ical back?

    I'm trying to figure out how to change my ICal back to the way it was before I upgrated my Desktop Mac computer.  I used to have a perfect calendar and since I upgraded, there are no side borders to the days when I'm on the "month" view.  It all looks like it is one big day running into eachother.  I hope it's an easy fix. If anyone knows what I'm trying to explain, please help me!!

    Configure the Extreme connected to the Hughes Net modem as your router. In other words in AirPort Utility, Network tab > Router Mode should be set to "DHCP and NAT". It will provide IP addresses to all the devices on your network.
    All other AirPort devices on your network should be configured as bridges: Router Mode "Off".
    You may want to configure static IP addresses for any equipment that is likely to be permanently installed. For them, there is no reason to have the Extreme issue an IP address, and they can keep the same one forever.
    The Microcell may be able to connect to the Express's LAN port such devices that have to handle voice or other real time audio or video streaming are generally best installed using a strictly wired connection. The same applies to the Sony TV and AppleTV. Keep them on a wired LAN served by the Extreme, avoiding any reliance on a wireless link if at all possible.
    The way to implement a complex network like yours is to add one device at a time. Ensure it connects reliably, then add another. You have a lot of work to do.
    WDS can be implemented even with new Extremes but its performance is likely to be so unacceptable that it would be nothing more than an exercise in frustration for you.

  • Unreadable music on iPod - music marked as 'other' PLEASE HELP!!!!!

    Please help!!! I connected my iPod today to upload some new music files and something appears to have gone wrong. I can't 'see' any of my music at all on the iPod OR on iTunes. The iPod Summary Screen on iTunes (ver 7) shows that there is over 20GB of information marked as 'other' on my iPod, plus my photos and videos, but it shows no music at all. Naturally, I could restore the factory settings and re-upload all my music from my external hard drive, but obviously I would prefer not to do so because it would mean a huge amount of time. Is there any suggestion as to how I might be able to force iTunes to recognise the music files on the iPod WITHOUT a restore? I have tried a 'soft' restore on the iPod unit itself but alas with no success. If there is anything that can be suggested I would be very, very grateful. Thanks, Sam

    Quite honestly, in the amount of time that it's taken you to get answere here, you could have restored it and reloaded the music!!
    That's the way to go.

  • I have an 8 gig ipod and 4 gigs is taken up by "other" please help me!

    I have the 8 gig 3rd generation i-pod and on my capasity i have 4 gigs taken up with other! I dont know what it could be because i deleted everything and it still said that i had it on there! I have been trying too figure it out for a long time and have tried everything i could think of! please help! thanks!

    Other can be Album Artwork, Notes, Contacts, Firmware etc. or (and this doesn't apply to the iPod Touch or iPhone which don't have the option to enabled for disk use), files that are on there if you are using the iPod as a removable storage device. If you feel that Other is being incorrectly reported then try restoring your iPod. Restoring will erase the iPod's hard drive, reload the software and put it back to default settings. Once the restore is complete follow the on screen instructions to name the iPod and automatically sync your songs and videos onto the fresh installation. Press Done and the iPod will appear in iTunes and start to sync. If you want to update manually or using selected playlists uncheck the box beside the sync automatically instruction and press Done, it will default to manual mode and you can choose whatever setting you like: Restoring iPod to factory settings with iTunes

  • Upgrading from snow leapord to mavericks, i couldn't opened app store, messenger, ibook,FaceTime, maps and other. please help

    upgrading from snow leapord to mavericks, i couldn't opened app store, messenger, ibook,FaceTime, maps and other. please help

    Try booting into the Safe Mode using your normal account.  Disconnect all peripherals except those needed for the test. Shut down the computer and then power it back up after waiting 10 seconds. Immediately after hearing the startup chime, hold down the shift key and continue to hold it until the gray Apple icon and a progress bar appear. The boot up is significantly slower than normal. This will reset some caches, forces a directory check, and disables all startup and login items, among other things. When you reboot normally, the initial reboot may be slower than normal. If the system operates normally, there may be 3rd party applications which are causing a problem. Try deleting/disabling the third party applications after a restart by using the application un-installer. For each disable/delete, you will need to restart if you don't do them all at once.
    Safe Mode
    Safe Mode - About
    If that doesn't work, do a backup. Boot to the Recovery Volume (command - R on a restart or hold down the option key during a restart and select Recovery Volume). Run Disk Utility Verify/Repair and Repair Permissions until you get no errors. Then reinstall the OS.
    OS X Recovery
    OS X Recovery (2)

  • Problems with disk permissions and others - Please help

    I recently updated to 10.5.8. When I open GoLive 6 i just get the spinning ball of death. When I try and run disk permissions it just scrolls and scrolls "reading permissions database and does nothing. I am on an iBook G4 1.33 and the system always seems to be dragging. Please help.
    Message was edited by: Marcus MacColonna

    HI Marcus,
    the system always seems to be dragging
    Check to see how much available space there is on the startup disk. Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. *Make sure you always have a minimum of 15% free disk space.*
    If free disk space isn't an issue, help here for the SSBOD
    Carolyn

  • I have zero kb out of 120 gb HDD 88gb is other :/ please help

    hello
    i have no space what so ever on my hard drive on my macbook air and 88gb of it is other and there is not files to delete or uninstal so i cant actually get any stoarge back please help :/

    Seven ways to free up drive space | Macworld

  • How to remove time dependent attributes from 0VENDOR- Please help

    Hi All,
    As part of master data enhancement, I had added some time dependent attributes to Vendor Master object. After activating, the respective time dependent tables were all created/activated.
    Now due to change of requirements, when I am trying to convert the time dependent attributes to non time dependent, I keep getting the activation error because it keeps giving a message "Unable to change the primary key" for MVENDOR. This view is getting the DATETO field because of the original activation. It is not removing that field and is causing the issues.
    Even if I adjust/delete the QVENDOR table in SE14 and then try to activate 0VENDOR, it is still retaining the DATETO field in the MVENDOR view and is recreating the QVENDOR table.
    I even tried to delete the time-dependent fields from the 0VENDOR (instead of just de-selecting the time dependent flag)...it is saving the changes..but giving activation error.
    Is it not possible to delete the time dependent attributes from the Master data...once they are added ?
    Please advice.
    Any help with this will be greatly greatly appreciated.
    At this point 0VENDOR is in inactive state.

    Hi Friends,
    First of all, sorry I did not get a chance to respond earlier. There was an issue with my p/w for some strange reason and could not log back in till today.
    Also, thank you for all your suggestions.
    However, the issue is now fixed. Basically I had already explored and tried every option suggested int his forum, but was still having issues.
    The problem was that there was another table in the system that had a reference to this Master Data table field (as a foreign key). After I removed the foreign key referece in the other table, then it let me proceed further.
    Thanks again..

Maybe you are looking for

  • Scheduling RSCRM_BAPI extract as a SAP job

    Hi all,    Of late I have trying to executing Bex query extract thru RSCRM_BAPI and needed a way to be able to schedule an user defined job so for that so that I have control in terms of when I execute the job.  I went thru SDN and found this Functio

  • Camera Raw - Enable RGB Tone Curves

    In Camera Raw, the Tone Curve Channel selection is disabled.  How can I enable it to allow me to adjust specific colors in Camera Raw? I'm using Photoshop CS5, Camera Raw version 6.7.0.339 on a Windows Vista 64 bit system, and my camera is a Nikon D9

  • Preview & Navigator issues

    I'm running LR 3 on Model Name: iMac   OSX 10.6.4   Model Identifier: iMac8,1   Processor Name: Intel Core 2 Duo   Processor Speed: 2.8 GHz   Number Of Processors: 1   Total Number Of Cores: 2   L2 Cache: 6 MB   Memory: 2 GB   Bus Speed: 1.07 GHz 1. 

  • Can't delete custom "My Workouts" in Nike+ application

    I have created some custom workouts for my running. For some freak reason, although in the past I was able to, now I can't delete these custom workouts. Yes, I press Edit, select the workout to delete, delete it, press Done... but by the moment I cha

  • Goto option for reports

    hi I have a report to report interface for two reprots. one is summary and other one details when i run the summary report in portal I have(with my user-id) the option "GOTO" to go to the details report. But the option "GOTO" is not available to the