Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chosen stealing focus. #1526

Open
razorfever opened this issue Aug 31, 2013 · 6 comments · May be fixed by #2716
Open

Chosen stealing focus. #1526

razorfever opened this issue Aug 31, 2013 · 6 comments · May be fixed by #2716

Comments

@razorfever
Copy link

Hi. I can not seem to get this to work. What I want is to put focus to an input field based on selection on chosen powered select element. Here's a fiddle to better illustrate the problem:

http://jsfiddle.net/ay9R9/

Both scenarios are identical but the first one is using Chosen and the other is not.
By selecting option 2 the focus should go to the input field. The one with chosen fails to work.

Thanks.

@stof
Copy link
Collaborator

stof commented Sep 3, 2013

A workaround is to delay the focus a little:

if (source == 2) {
    setTimeout(function () {
        $('#testfield').focus();
    }, 1);
}

@stof
Copy link
Collaborator

stof commented Sep 3, 2013

Note that it works even when using 0 as timeout (which still delays the execution a bit as it will runs during the next iteration of the event loop)

@koenpunt
Copy link
Collaborator

koenpunt commented Sep 4, 2013

With a delay it works, but the visual 'focus' is still there (blue border). I think there has be a change in when to set focus on Chosen. Marking it as a bug.

@rfryer
Copy link

rfryer commented Nov 20, 2013

The delay doesn't seem to work for me. I was using a workaround overriding AbstractChosen.prototype.input_blur: but since V1 this no longer works because the AbstractChosen has been hidden.

Should I now revert to V0.9.15, or is there a better approach?

Thanks

@asantos
Copy link

asantos commented Nov 12, 2014

I'm experiencing the same problem, it seems it has still not been fixed in 1.1.0 - i rolled back to 0.9.8 until the issue can be solved.

BTW, here's a workaround for this issue (takes care of both the input-focus and the chosen-focus-style)

setTimeout(function(){
$('#your_select_chosen').removeClass('chosen-container-active');
$('#your_input').focus();
}, 0);

@1bnr
Copy link

1bnr commented Nov 19, 2019

this solution doesn't work for me unless I crank the timeout up to 100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants