From 06d0955074f79de553cc34fbf945045dc458e064 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 30 Mar 2012 12:07:19 -0700 Subject: feat(ngModel): update model on each key stroke (revert ngModelInstant) It turns out that listening only on "blur" event is not sufficient in many scenarios, especially when you use form validation you always had to use ngModelnstant e.g. if you want to disable a button based on valid/invalid form. The feedback we got from our apps as well as external apps is that the ngModelInstant should be the default. In the future we might provide alternative ways of suppressing updates on each key stroke, but it's not going to be the default behavior. Apps already using the ngModelInstant can safely remove it from their templates. Input fields without ngModelInstant directive will start propagating the input changes into the model on each key stroke. --- test/ng/directive/formSpec.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'test/ng/directive/formSpec.js') diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index 5c34b5ad..491a31db 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -1,7 +1,7 @@ 'use strict'; describe('form', function() { - var doc, control, scope, $compile; + var doc, control, scope, $compile, changeInputValue; beforeEach(module(function($compileProvider) { $compileProvider.directive('storeModelCtrl', function() { @@ -14,9 +14,14 @@ describe('form', function() { }); })); - beforeEach(inject(function($injector) { + beforeEach(inject(function($injector, $sniffer) { $compile = $injector.get('$compile'); scope = $injector.get('$rootScope'); + + changeInputValue = function(elm, value) { + elm.val(value); + browserTrigger(elm, $sniffer.hasEvent('input') ? 'input' : 'change'); + }; })); afterEach(function() { @@ -126,10 +131,8 @@ describe('form', function() { var inputA = doc.find('input').eq(0), inputB = doc.find('input').eq(1); - inputA.val('val1'); - browserTrigger(inputA, 'blur'); - inputB.val('val2'); - browserTrigger(inputB, 'blur'); + changeInputValue(inputA, 'val1'); + changeInputValue(inputB, 'val2'); expect(scope.firstName).toBe('val1'); expect(scope.lastName).toBe('val2'); -- cgit v1.2.3