0

focus() on anything that inherits from KOntx.element.Container not working??

Hi there,

In both the developer guide and on forum posts I have seen that calling .focus() on a control will move the focus to that control when the page loads.
However I've tried this out on a series of controls (button, grid, pageindicator) within the sidebar view and it doesn't seem to work. The focus stays on the topmost button. Also I see the following in the logs (in this example I was calling .focus() on a pageindicator):

WIDGET VIEW WINDOW DELAYING FOCUS TO VIEW(Frame394[0xb1b2c1a8 REFS=2] Frame "") NODE([0xb1b2be68 REFS=4 DOC=0xaff2180 DEPTH=0x3 SCRIPTOBJ=0xb1b2c7c0 JSOBJ=0xb1b20128] <frame> 'ControlPageIndicator-68.element' )

I've looked through the Konfabulator code and element.js line 493 looks to be the method that is called. This calls el.focus which i think is producing the above meesage but that is then in the binary code so I can't dig any deeper.

I'm using framework 1.1 and the latest WDK.

Am I doing something wrong or are we not able to change the focused control from the default when going to a view?

Kind Regards,

Penny.

by
18 Replies
  • QUOTE (Penny @ Jul 10 2009, 06:03 AM) <{POST_SNAPBACK}>
    Hi there,

    In both the developer guide and on forum posts I have seen that calling .focus() on a control will move the focus to that control when the page loads.
    However I've tried this out on a series of controls (button, grid, pageindicator) within the sidebar view and it doesn't seem to work. The focus stays on the topmost button. Also I see the following in the logs (in this example I was calling .focus() on a pageindicator):

    WIDGET VIEW WINDOW DELAYING FOCUS TO VIEW(Frame394[0xb1b2c1a8 REFS=2] Frame "") NODE([0xb1b2be68 REFS=4 DOC=0xaff2180 DEPTH=0x3 SCRIPTOBJ=0xb1b2c7c0 JSOBJ=0xb1b20128] <frame> 'ControlPageIndicator-68.element' )

    I've looked through the Konfabulator code and element.js line 493 looks to be the method that is called. This calls el.focus which i think is producing the above meesage but that is then in the binary code so I can't dig any deeper.

    I'm using framework 1.1 and the latest WDK.

    Am I doing something wrong or are we not able to change the focused control from the default when going to a view?

    Kind Regards,

    Penny.


    Penny,

    Where are you trying to call the focus?
    0
  • in updateView method of a sidebar view.
    0
  • QUOTE (Penny @ Jul 10 2009, 07:15 AM) <{POST_SNAPBACK}>
    in updateView method of a sidebar view.


    Focus isn't controllable inside an updateView as you don't have focus yet. The focus management should be handled inside a focusView() method you provide on your view class.

    -Jeremy
    0
  • I tried the same thing within focusView() and still get the same problem.
    0
  • A few things to investigate:

    * The value returned when calling .focus() on the underlying Konfabulator element (Frame) -

    In your focusView method, instead of something like:

    CODE
    this.controls.pageindicator.focus();


    try:

    CODE
    var focusresult = this.controls.pageindicator.element.focus();
    log("... the result of trying to focus the element directly:", focusresult);


    * The dimensions of the control you're trying to focus -

    A Frame (the core element of Containers and Buttons) must have at least one pixel of height and width to be focusable. Calling .focus() on a Frame with a 0-pixel width and height produces exactly the log you provided.

    * And finally, the focus state of the tree above your frame - if any of the parent nodes have navigationEnabled = false, you're not going to get a focus.
    0
  • Hi Keville,

    Thanks for your suggestions.

    1. I had tried focusing the element directly and that doesn't work either .... The following code....

    focusView: function() {
    var focusresult = this.controls.pageIndicator.element.focus();
    log("... the result of trying to focus the element directly: ", focusresult);

    },


    ...results in.....

    WM 00:00:12:056: [T:14431] gainfocus: view-DynamicMenu
    WM 00:00:12:056: [T:14431] [KONtx/BBC Journalism] {SidebarView-96} :: _setInitialFocus
    WM 00:00:12:057: [T:14431] [KONtx/BBC Journalism] {ControlPageIndicator-111} :: focus
    EM 00:00:12:057: [T:14431] WIDGET VIEW WINDOW DELAYING FOCUS TO VIEW(Frame416[0xb3b1630 REFS=2] Frame "") NODE([0xb3b1338 REFS=4 DOC=0xa940818 DEPTH=0x3 SCRIPTOBJ=0xb415428 JSOBJ=0xafda138] <frame> 'ControlPageIndicator-111.element' )
    WM 00:00:12:059: [T:14431] ... the result of trying to focus the element directly: false


    2. The dimensions of the control - the page indicator (KONtx.control.PageIndicator) is definately more than 1 pixel high and wide.

    3. I get the same issue with every control I have. KOntx grids (controls and element versions), pageindicators, buttons etc. All of these controls focus correctly on navigation. I just can't get them to focus programmatically. (and i can only assume if they get focus by navigation then they don't have navigationEnabled == false)

    Perhaps .focus() just doesn't work??
    0
  • Hi Penny!

    What is the exact version of the WDK you are using?

    -Jeremy
    0
  • I have just discovered that this doesn't work on the first entry into the view, if we go back to it later .focus() does work and successfully focuses on the pageindicator.

    So the question is howcome it doesn't work first time? Do we need to put a wait in to make it work? (which isn't really ideal). What is the very last method to be called on loading a view?
    0
  • QUOTE (Penny @ Aug 3 2009, 08:54 AM) <{POST_SNAPBACK}>
    I have just discovered that this doesn't work on the first entry into the view, if we go back to it later .focus() does work and successfully focuses on the pageindicator.

    So the question is howcome it doesn't work first time? Do we need to put a wait in to make it work? (which isn't really ideal). What is the very last method to be called on loading a view?



    I have been having the same issue. Was this answered and/or resolved by Yahoo...or anyone?

    Thanks,
    Paul
    0
  • QUOTE (Paul @ Dec 1 2009, 10:09 AM) <{POST_SNAPBACK}>
    I have been having the same issue. Was this answered and/or resolved by Yahoo...or anyone?

    Thanks,
    Paul

    Try overriding the methods focusView and setInitialFocus in your view, and set your focus in these methods.
    0
  • QUOTE (Steve @ Dec 1 2009, 11:51 AM) <{POST_SNAPBACK}>
    Try overriding the methods focusView and setInitialFocus in your view, and set your focus in these methods.


    Thank you for your reply, but it is still not working. Here's some simple test code demonstrating this not working:

    var MainView = new KONtx.Class({
    ClassName: 'MyCustomMainView',

    Extends: KONtx.system.SidebarView,

    createView: function() {

    this.controls.ueiButtonMyButton = new KONtx.control.TextButton({
    label: 'MyButton',
    id: "ueiButtonMyButton",
    guid: "ueiButtonMyButton",
    focus: true,
    styles: {
    vOffset: 150,
    textAlign: 'left',
    hAlign: 'left',
    height: 48,
    width: selectionButtonWidth,
    },
    events: {
    onSelect: function(event) {
    }
    }
    }).appendTo(this);

    this.controls.ueiButtonMyButton2 = new KONtx.control.TextButton({
    label: 'MyButton2',
    id: "ueiButtonMyButton2",
    guid: "ueiButtonMyButton2",
    focus: true,
    styles: {
    vOffset: 250,
    textAlign: 'left',
    hAlign: 'left',
    height: 48,
    width: selectionButtonWidth,
    },
    events: {
    onSelect: function(event) {
    }
    }
    }).appendTo(this);
    },


    updateView: function() {
    },


    focusView: function() {
    UeiLog("focusView here 1");

    var focusresult = this.controls.ueiButtonMyButton2.focus();

    UeiLog("focusresult = " + focusresult);
    UeiLog("focusView here 2");
    },

    setInitialFocus: function() {
    UeiLog("setInitialFocus here 1");

    var focusresult = this.controls.ueiButtonMyButton2.focus();

    UeiLog("focusresult = " + focusresult);
    UeiLog("setInitialFocus here 2");
    },


    });
    0
  • This appears to be a bug when attempting to set focus in a home view.

    This is a hack, but is one way I have gotten around the issue. Basically, I set focus to false for every element except the one I want to receive focus. Then I re-enable focus in the focus view method of the other elements. Not pretty, but appears to work.

    CODE
    var HomeView = new KONtx.Class({
    ClassName : 'HomeView',
    Extends : KONtx.system.SidebarView,

    createView : function() {
    this.controls.button1 = new KONtx.control.TextButton({
    label : 'Button 1',
    focus : false
    }).appendTo(this);

    this.controls.button2 = new KONtx.control.TextButton({
    label : 'Button 2',
    styles : {
    vOffset : this.controls.button1.outerHeight
    }
    }).appendTo(this);

    this.controls.button3 = new KONtx.control.TextButton( {
    label : 'Button 3',
    focus : false,
    styles : {
    vOffset : this.controls.button2.outerHeight
    }
    }).appendTo(this);
    },

    focusView : function() {
    this.controls.button1.element.wantsFocus = true;
    this.controls.button3.element.wantsFocus = true;
    }
    });
    0
  • I'm having the same issue but is happening in a fullscreenview. (using latest WDK)

    the focus is not set just on initial loading of view and message with "WIDGET VIEW DELAY FOCUS..." comes when setting focus.
    on subsequent calls to the view the focus works fine.

    is there a fix or a different method to ensure this works? (besides the hack Steve posted above?)
    0
  • I faced the same problem and used a simple workaround - calling focus() method after a little delay. Code example:

    CODE
    KONtx.utility.timer.setTimeout(function(){
    self.controls.submitButton.focus();
    }, 1);


    This worked for me.
    0
  • We're looking into this.
    0
  • Any updates on this? THere haven't been any posts or updates on this topic since Jun 29...

    QUOTE (Benjamin Toll @ Jun 29 2010, 06:21 PM) <{POST_SNAPBACK}>
    We're looking into this.
    0
  • focusView : function() {
    if ( showLogout==true)
    {
    this.controls.Button1.visible = true;
    this.controls.Button2.visible = false;
    this.controls.Button1.focus();
    this.controls.Button1.element.wantsFocus = true;
    }
    else
    {
    this.controls.Button2.visible = true;
    this.controls.logoutButton.visible = false;
    this.controls.Button1.focus();
    this.controls.Button2.element.wantsFocus = true;
    }
    }

    The above code worked for me
    0
  • This is still an issue in the latest WDK almost 3 years later. Is there a fix for this yet?

    0

Recent Posts

in General - Yahoo! TV Widgets