• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

can't move focus to the control because it is invisible

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When trying to get focus on an element in IE I get the following javascript error message:

'Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus'

I can resolve it by the code above. But not sure what I'm checking. I realise that first checking visibility of the input type ie whether it's hidden. Whether the style of the display is set to not display and whether that element has disabled. I'm not 100% certain about the second check the display. This fix works but would like to understand better what the 2nd check means.
Any help would be greatly appreciated.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second one is to check if CSS's style.display property has been set to "none", which would mean that the component exists but is not displayed.
I'm not sure if it's the correct way to check if you can set the focus or not. Do you intend to do it for all your focusable elements ?
 
russell stoneyroyd
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the response.
Yeah basically there is a bunch of html input types rendered on a page the code loops through to look for the first focusable input type and then gives focus to it. So this is the check to see what is focusable. Have tried element.focus != null but this didn't work.
Do I make sense?
 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check up in addition property "visibility". However, the parent of an element can be invisible. Therefore, the call of a method "focus" is better for concluding in the block "try".
 
Ranch Hand
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrey,

3 years later your solution has helped me
 
Greenhorn
Posts: 1
jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Andrey V. Ovcharenko wrote:You can check up in addition property "visibility". However, the parent of an element can be invisible. Therefore, the call of a method "focus" is better for concluding in the block "try".



Thanks Andrey, try/catch the method of focus is the simplest way to fix the IE bug!
DO NOT use so many if judgement, who works well will work well, let it to be!

@see
http://bugs.jquery.com/ticket/10859
http://bugs.jquery.com/ticket/11054

WHY jQuery DO NOT fix the "bug"?

In 1.6.x we trapped and discarded *any* errors thrown by an inline event handler.
That is not good because it masks problems that the handler may have.
We are trying to remove any of these omnibus try/catch situations in the jQuery code base to prevent that.
So this error was occurring before, but just masked.

I think IE8 is justified in being upset that you're trying to set focus to an element the user cannot see or interact with.
Most other browsers seem to ignore it since it's not a valid request, but there's no W3C guideline that I know of for what to do when someone asks to focus an invisible element.
An error is probably better than silence when it comes to debugging.

If this is being caused by a plugin then the plugin should be fixed.
Solutions include showing the element before setting focus to it, or using .triggerHandler() if you just want to run handlers and not actually set focus.

by dmethvin


This resolution seems a bit strange to me, but perhaps I don't quite understand jQuery goal.
From where I stand - jQuery is suppose to provide consistent behaviour across browsers and this is not it.

by anonymous


jQuery provides consistent behavior for a valid set of inputs and actions.
Trying to focus an invisible element isn't in that set.
Making things consistent across browsers shouldn't mean making all browsers hide an mistake if any of them hide the mistake.

by dmethvin

 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because, as pointed out, there is no bug to fix.

"ufologist dream", please check your private messages for an important administrative matter. Thanks.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic