From 586ce70b8b65f7c0fb63cd175252a3b2ac906c91 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Tue, 4 Dec 2018 23:18:53 +0530 Subject: [PATCH] portico: Auto-detect field to focus for registration page. This replaces the manually-curated logic for which field to focus. --- static/js/portico/signup.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/static/js/portico/signup.js b/static/js/portico/signup.js index 4781da368d..a126a63f75 100644 --- a/static/js/portico/signup.js +++ b/static/js/portico/signup.js @@ -45,14 +45,13 @@ $(function () { } if ($("#registration").length > 0) { - if ($("#id_team_name").length === 1) { - common.autofocus('#id_team_name'); - } else if ($('#id_email').length === 1 && !$('#id_email').attr('disabled')) { - common.autofocus('#id_email'); - } else if ($("#source_realm_select").length === 1) { - common.autofocus('#source_realm_select'); - } else { - common.autofocus('#id_full_name'); + // Check if there is no input field with errors. + if ($('.help-inline:not(:empty)').length === 0) { + // Find the first input field present in the form that is + // not hidden and disabled and store it in a variable. + var firstInputElement = $("input:not(:hidden, :disabled):first"); + // Focus on the first input field in the form. + common.autofocus(firstInputElement); } // reset error message displays