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. --- src/ngScenario/Scenario.js | 2 +- src/ngScenario/dsl.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ngScenario') diff --git a/src/ngScenario/Scenario.js b/src/ngScenario/Scenario.js index cd3c335f..7335d5de 100644 --- a/src/ngScenario/Scenario.js +++ b/src/ngScenario/Scenario.js @@ -327,7 +327,7 @@ function browserTrigger(element, type, keys) { (function(fn){ var parentTrigger = fn.trigger; fn.trigger = function(type) { - if (/(click|change|keydown|blur)/.test(type)) { + if (/(click|change|keydown|blur|input)/.test(type)) { var processDefaults = []; this.each(function(index, node) { processDefaults.push(browserTrigger(node, type)); diff --git a/src/ngScenario/dsl.js b/src/ngScenario/dsl.js index 8a1bccb1..7f399394 100644 --- a/src/ngScenario/dsl.js +++ b/src/ngScenario/dsl.js @@ -198,12 +198,13 @@ angular.scenario.dsl('binding', function() { */ angular.scenario.dsl('input', function() { var chain = {}; + var supportInputEvent = 'oninput' in document.createElement('div'); chain.enter = function(value, event) { return this.addFutureAction("input '" + this.name + "' enter '" + value + "'", function($window, $document, done) { var input = $document.elements('[ng\\:model="$1"]', this.name).filter(':input'); input.val(value); - input.trigger(event || 'blur'); + input.trigger(event || supportInputEvent && 'input' || 'change'); done(); }); }; -- cgit v1.2.3