How to disable the drop down function of combo box on certain conditions?

Posted by Angeline Aarthi on Stack Overflow See other posts from Stack Overflow or by Angeline Aarthi
Published on 2009-11-21T07:43:37Z Indexed on 2010/04/01 2:03 UTC
Read the original article Hit count: 397

Filed under:
|
|
|

Hi, I have a combo box in my application. I also have a variable called "Status". I want the combo box to be enabled only when the value of the Status variable is 5 or 6. Otherwise, I should not be able to change the value in the combo box. It should have the previous value only..

I had written a click event to disable the combo box. But even though the combo box is disabled, I get the drop down list of the combo box, and If I select some othe value in the drop down,it changes..Only after that it gets disabled..

How to avoid this? I want the drop down function itself to be disabled. This is the code I have written. Someone guide me.

<mx:FormItem label="Review Status:" width="100%" horizontalAlign="right">
  <mx:HBox>
     <mx:Label  width="30"/>
        <mx:ComboBox id="reviewStatus" dataProvider="{Status}" 
                     width="150" click="onStatusChange(event)"/> 
  </mx:HBox>

Action Script part:

private function onStatusChange(event:Event):void
{
  var i:int;
  for(i=0;i<defectDetails.length;i++)
  {
    var defStatusId:String=defectDetails.getItemAt(i).DefectStatusId;
    if(defStatusId=="5"){
               reviewStatus.enabled=true;
    }  
    else  if(defStatusId=="6"){
               reviewStatus.enabled=true;
    }
    else{
               reviewStatus.enabled=false;
             //reviewStatus.selectedItem.label="Review";
             reviewStatus.toolTip="Status can be changed only if Defect Status is Verified or Deferred.";

              //Alert.show("Status can be changed only if defect status is verified or deferred");
    }
   }
  }

If I use Change event also, for the first time the value is changed. Only after that,the combo box is disabled. How to retain the same value and disable the combo box when the status is not 5 or 6?

© Stack Overflow or respective owner

Related posts about flex

Related posts about onchange