Permalink
Browse files

Merge pull request #672 from SteveSanderson/672-hasfocus-lost-dependency

hasfocus: current master breaks hasfocus example (click to focus)
  • Loading branch information...
2 parents c420788 + 2aee242 commit 46c1487f337f6bf4ebb37a706b0dafaa4ba2234c @mbest mbest committed Oct 17, 2012
Showing with 8 additions and 1 deletion.
  1. +7 −0 spec/defaultBindings/hasfocusBehaviors.js
  2. +1 −1 src/binding/defaultBindings/hasfocus.js
@@ -34,6 +34,13 @@ describe('Binding: Hasfocus', {
testNode.childNodes[1].focus();
ko.utils.triggerEvent(testNode.childNodes[0], "focusout");
value_of(model.myVal()).should_be(false);
+
+ // If the model value becomes true after a blur, we re-focus the element
+ // (Represents issue #672, where this wasn't working)
+ var didFocusExpectedElement = false;
+ ko.utils.registerEventHandler(testNode.childNodes[0], "focusin", function() { didFocusExpectedElement = true });
+ model.myVal(true);
+ value_of(didFocusExpectedElement).should_be(true);
},
'Should set a non-observable value to be true on focus and false on blur': function() {
@@ -26,8 +26,8 @@ ko.bindingHandlers['hasfocus'] = {
ko.utils.registerEventHandler(element, "focusout", handleElementFocusOut); // For IE
},
'update': function(element, valueAccessor) {
+ var value = ko.utils.unwrapObservable(valueAccessor());
if (!element[hasfocusUpdatingProperty]) {
- var value = ko.utils.unwrapObservable(valueAccessor());
value ? element.focus() : element.blur();
ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, value ? "focusin" : "focusout"]); // For IE, which doesn't reliably fire "focus" or "blur" events synchronously
}

0 comments on commit 46c1487

Please sign in to comment.