10 Replies Latest reply: Jan 28, 2013 4:42 AM by mqhnow1 RSS

    tabEnabled property issue.

    jkorona

      I have problem with changing value of tabEnabled property in runtime. My goal is to prevent user setting focus on components by tab key in some specific situations.

      I will start from sample code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
           
           <mx:Script>
                <![CDATA[
                     
                     [Bindable]
                     private var flag : Boolean = false;
                     
                ]]>
           </mx:Script>
           
           <mx:Button/>
           <mx:ComboBox tabEnabled="{flag}"/>
           <mx:ComboBox tabEnabled="{flag}"/>
           <mx:ComboBox tabEnabled="{flag}"/>
           <mx:ComboBox tabEnabled="{flag}"/>
           <mx:Button>
                <mx:click>
                     <![CDATA[
                          flag = !flag;
                     ]]>
                </mx:click>
           </mx:Button>
           
      </mx:Application>
      
       
      

       

      If initially value of tabEnabled is set to true, then I can change it in runtime many times without any problems. But if I set initially value of tabEnabled to false then even if I change it to true in runtime, component behaves as if it had this property turned off - can't set focus using tab key.

      Maybe solution for this problem is very simple, but actually I have no idea how to solve it, so I'm looking forward on your help.

      BTW. I am using Flex SDK 3.5 FP 10.1.

        • 1. Re: tabEnabled property issue.
          Flex harUI Adobe Employee

          Looks like a bug.  File it in bugs.adobe.com/jira.  I'd say the workaround

          is probably to initialize it to true and set it back to false in

          applicationComplete handler.

          • 2. Re: tabEnabled property issue.
            jkorona Community Member

            I tried to override tabEnabled setter:

             

                      public override function set tabEnabled(enabled:Boolean):void {
                           if(!initialized && !enabled) {
                                super.tabEnabled = true;
                                addEventListener(FlexEvent.CREATION_COMPLETE, function() : void {
                                     tabEnabled = enabled;
                                });
                           } else {
                                super.tabEnabled = enabled;
                           }
                      }
            

             

            but it didn't help. This is very strange...

            • 3. Re: tabEnabled property issue.
              Flex harUI Adobe Employee

              I don't understand what you were trying to do.  Did my suggestion not work?

              • 4. Re: tabEnabled property issue.
                jkorona Community Member

                Code which is pasted in the first post, is very simplified. I need create custom component that can be dynamically added in runtime, so workaround with applicationComplete would be not enought. I checked the source and it seems that I found the problem : components with initially tabEnabled=false, are not added to focusableObjects array in FocusManager, which is used to determine the next object in focus order. So this is probably reason, now I need workaround for this.

                • 5. Re: tabEnabled property issue.
                  Flex harUI Adobe Employee

                  I think you can just add them with tabEnabled=true and set it to false on

                  creationComplete.  It shouldn't require overriding tabEnabled

                  • 6. Re: tabEnabled property issue.
                    jkorona Community Member

                    My code does exactly what you described. The only difference is that this is done inside the control, what is needed to make this solution reusable. But in both cases, this will not work. If I use applicationComplete instead of creationComplete event, as you wrote before, it will works, but this is sufficient only for the simplest cases. If I create components dynamically and adds them to the display list runtime, for what events I should listen?

                    • 7. Re: tabEnabled property issue.
                      Flex harUI Adobe Employee

                      CreationComplete should be sufficient.  TabEnabled should default to true on

                      these components so the component should get added to the FocusManager in

                      the call to addChild, then you would set it to false on creationComplete.

                       

                      Maybe a helper function like

                       

                      Function addTabDisbledComponent(parent:DisplayObjectContainer,

                      component:IUIComponent):void

                      {

                          component.addEventListener(FlexEvent.CREATION_COMPLETE,

                      tabDisableHandler);

                          parent.addChild(component);

                      }

                       

                      Function tabDisableHandler(event:Event):void

                      {

                          event.target.removeEventListener(FlexEvent.CREATION_COMPLETE,

                      tabDisableHandler);

                          event.target.tabEnabled = false;

                      }

                      • 8. Re: tabEnabled property issue.
                        jkorona Community Member

                        Your solution works for certain situations, but not for all. My requirement was to create workaround inside of component, and found a way that satisfies me:

                             public override function set tabEnabled(enabled:Boolean):void {
                                  super.tabEnabled = enabled;
                                  if(enabled && focusManager)
                                       focusManager.mx_internal::form.dispatchEvent(new Event("tabChildrenChange"));
                             }
                        

                        FocusManager listen on tabChildrenChange event, and refresh focusableObjects array. Then user can navigate using tab key.

                        Maybe this is not attractive solution, but required since tabEnabled not working as it should. @Flex_harUI - thanks a lot for your help!

                        • 9. Re: tabEnabled property issue.
                          jkorona Community Member

                          Summary : FocusManager in Flex SDK 3.5 contains bug, which prevents use of keyboard navigation, when tabEnabled property is initially set to false, and changed in runtime. There are several workarounds to this problem, which can be found in this topic.

                          • 10. Re: tabEnabled property issue.
                            mqhnow1

                            OMG!!

                            I can't believe such an obvious but still haven't been fixed 3 years after it was reported.