Stache interfering with setting focus


#1

On my login page, I want to set the focus on the first field.

I added a helper to do so

can.stache.registerHelper('placeFocus',function(){
    setTimeout(()=>{
        $($('input')[0]).focus().css('background', 'yellow');
    }, 10);
})

The jquery call that is the guts works correctly in the console. The timeout allows the DOM to complete before it runs. If I console.dir() the selected DOM object, it’s the correct one. When I set it to a stupidly long length of time (10000), it still does nothing.

What am I missing?


#2

Hi @tqwhite, I tried to replicate the issue in a JS Bin but it seems to work correctly for me in Chrome and Safari: http://jsbin.com/jiromitodu/1/edit?html,js,output

Does it work for you? If so, can you replicate the issue in another JS Bin?


#3

Use the focused special event. Todomvc guide shows it. http://canjs.com/doc/can-util/dom/attr/attr.special.focused.html