From 71efd51bffda3010e5a155b74f904b4eb2879146 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 2 Jun 2014 22:35:33 -0500 Subject: [PATCH] fix(popup): focus on first input Closes #822 --- js/angular/service/popup.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/angular/service/popup.js b/js/angular/service/popup.js index b31472ae357..2b13a82734b 100644 --- a/js/angular/service/popup.js +++ b/js/angular/service/popup.js @@ -413,13 +413,16 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume } function focusInputOrButton(element) { - var inputs = element[0].querySelectorAll('input'); - if (!inputs.length) { - inputs = element[0].querySelectorAll('button'); + var focusOn = element[0].querySelector('input[autofocus]'); + if (!focusOn) { + focusOn = element[0].querySelector('input'); + if (!focusOn) { + var buttons = element[0].querySelectorAll('button'); + focusOn = buttons[buttons.length-1]; + } } - var last = inputs[inputs.length-1]; - if(last) { - last.focus(); + if(focusOn) { + focusOn.focus(); } }