From 5f327e851d02f13fd3354ddc0148c65489609802 Mon Sep 17 00:00:00 2001 From: raytiley Date: Thu, 26 Feb 2015 12:54:27 -0500 Subject: [PATCH] [BUGFIX beta] update lastValue of AttrNode even when not rerendering Fixes 10541 --- .../tests/helpers/input_test.js | 20 +++++++++++++++++++ .../ember-views/lib/attr_nodes/attr_node.js | 1 + 2 files changed, 21 insertions(+) diff --git a/packages/ember-htmlbars/tests/helpers/input_test.js b/packages/ember-htmlbars/tests/helpers/input_test.js index cd065e32501..67170f8dc7f 100644 --- a/packages/ember-htmlbars/tests/helpers/input_test.js +++ b/packages/ember-htmlbars/tests/helpers/input_test.js @@ -102,6 +102,26 @@ QUnit.test("cursor position is not lost when updating content", function() { equal(input.selectionEnd, 3, 'cursor position was not lost'); }); +QUnit.test("input can be updated multiple times", function() { + equal(view.$('input').val(), "hello", "precondition - renders text field with value"); + + var $input = view.$('input'); + var input = $input[0]; + + run(null, set, controller, 'val', ''); + equal(view.$('input').val(), "", "updates first time"); + + // Simulates setting the input to the same value as it already is which won't cause a rerender + run(function() { + input.value = 'derp'; + }); + run(null, set, controller, 'val', 'derp'); + equal(view.$('input').val(), "derp", "updates second time"); + + run(null, set, controller, 'val', ''); + equal(view.$('input').val(), "", "updates third time"); +}); + QUnit.module("{{input type='text'}} - static values", { setup: function() { diff --git a/packages/ember-views/lib/attr_nodes/attr_node.js b/packages/ember-views/lib/attr_nodes/attr_node.js index db8cf381502..fdc6d53c13e 100644 --- a/packages/ember-views/lib/attr_nodes/attr_node.js +++ b/packages/ember-views/lib/attr_nodes/attr_node.js @@ -53,6 +53,7 @@ AttrNode.prototype.render = function render(buffer) { // If user is typing in a value we don't want to rerender and loose cursor position. if (this.attrName === 'value' && this._morph.element.value === value) { + this.lastValue = value; return; }