hasfocus fix for focussing hidden elements (focus asynchronously) #671

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

Contributor

Check it out here: http://jsfiddle.net/mhrf2/

I'm not really sure if this opens up for race conditions; but it is better than now, at least.

@lcorneliussen lcorneliussen Focus asynchronously if element is hidden
I'm not really sure if this opens up for race conditions; but it is better than now, at least.
Check it out here: http://jsfiddle.net/mhrf2/
2ad7986
Contributor

Candidate for superseeding #355

Contributor

Hm. Doesn't fix my real problem. binding and element seem to go out of sync on my end. Element is not focussed, but the observable is true... computed dependents are not updated...

Contributor

Ok. My problem is this:
#672

Current master breaks backwards-compat - click to focus does not work.

Contributor

Hm. Doesn't fix my real problem. binding and element seem to go out of sync on my end.

Does this mean you are no longer suggesting this solution?

In general, we try hard not to do stuff asynchronously within Knockout (except when you explicitly opt into it, as in the throttle extender). The reason is that once something starts happening asynchronously and you have no way of knowing exactly when, then it quickly becomes impossible to chain together sequences of operations except by adding yet more setTimeout hacks.

I'll close #671 now and leave #355 open to represent the basic concern about focusing hidden elements. Please let me know if you disagree!

Contributor

did the last comment on #355

the issue is still current - i still have a fork running :(

This code worked for me:

var koHasFocusUpdateFuction = ko.bindingHandlers.hasfocus.update;
ko.bindingHandlers.hasfocus.update = function(element, valueAccessor) {
if ($(element).is(":visible"))
koHasFocusUpdateFuction(element, valueAccessor);
};

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