From f2236eb061a6fb7cc8fb645fe21d8194966cbc86 Mon Sep 17 00:00:00 2001 From: Austin McKinley Date: Thu, 7 Feb 2019 11:32:48 -0800 Subject: [PATCH] Autofocus form control for adding TOTP codes Summary: Ref D20122. This is something I wanted in a bunch of places. Looks like at some point the most-annoying one (autofocus for entering TOTOP codes) already got fixed at some point. Test Plan: Loaded the form, got autofocus as expected. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D20128 --- .../auth/factor/PhabricatorTOTPAuthFactor.php | 1 + src/view/form/control/PHUIFormNumberControl.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php b/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php index ba6613c014..7e77dfc11a 100644 --- a/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php +++ b/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php @@ -128,6 +128,7 @@ final class PhabricatorTOTPAuthFactor extends PhabricatorAuthFactor { ->setLabel(pht('TOTP Code')) ->setName('totpcode') ->setValue($code) + ->setAutofocus(true) ->setError($e_code)); } diff --git a/src/view/form/control/PHUIFormNumberControl.php b/src/view/form/control/PHUIFormNumberControl.php index 26e7e03955..c577bebbd0 100644 --- a/src/view/form/control/PHUIFormNumberControl.php +++ b/src/view/form/control/PHUIFormNumberControl.php @@ -3,6 +3,7 @@ final class PHUIFormNumberControl extends AphrontFormControl { private $disableAutocomplete; + private $autofocus; public function setDisableAutocomplete($disable_autocomplete) { $this->disableAutocomplete = $disable_autocomplete; @@ -13,6 +14,15 @@ final class PHUIFormNumberControl extends AphrontFormControl { return $this->disableAutocomplete; } + public function setAutofocus($autofocus) { + $this->autofocus = $autofocus; + return $this; + } + + public function getAutofocus() { + return $this->autofocus; + } + protected function getCustomControlClass() { return 'phui-form-number'; } @@ -34,6 +44,7 @@ final class PHUIFormNumberControl extends AphrontFormControl { 'disabled' => $this->getDisabled() ? 'disabled' : null, 'autocomplete' => $autocomplete, 'id' => $this->getID(), + 'autofocus' => ($this->getAutofocus() ? 'autofocus' : null), )); }