From 29dfb9fe7eaf099436aec30b56ac3a91dfc99f7a Mon Sep 17 00:00:00 2001 From: Mario Volke Date: Tue, 17 Jun 2014 14:54:06 +0200 Subject: [PATCH] addressInput directive: prevent race conditions with focusMe directive, prevent loosing focus when hitting space in empty input field --- src/js/controller/write.js | 14 ++++++++------ src/tpl/write.html | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/js/controller/write.js b/src/js/controller/write.js index 5d7cafc..4d9728c 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -531,12 +531,14 @@ define(function(require) { // catch space, comma, semicolon e.preventDefault(); - // create new field input - addInput(field, scope); - // find next input and focus - var nextId = fieldName + (index + 1); - document.getElementById(nextId).focus(); - + // add next field only if current input is not empty + if(field[index].address) { + // create new field input + addInput(field, scope); + // find next input and focus + var nextId = fieldName + (index + 1); + document.getElementById(nextId).focus(); + } } else if ((code === 8 || code === 46) && !field[index].address && field.length > 1) { // backspace, delete on empty input // remove input diff --git a/src/tpl/write.html b/src/tpl/write.html index bbc5706..88d6d57 100644 --- a/src/tpl/write.html +++ b/src/tpl/write.html @@ -14,7 +14,7 @@

- +