From baf861224aabf8e102862950aac4764cb816cd2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 16 Oct 2013 18:57:12 +0200 Subject: [PATCH] Simplify boolean attribute handling for Html::input in templates The Html class supports this handy shorthand. Change-Id: Ie34790fa650c7ecad02c2d91130bf0db9172ea3f --- includes/templates/Usercreate.php | 3 ++- includes/templates/Userlogin.php | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/includes/templates/Usercreate.php b/includes/templates/Usercreate.php index 7a4b9f20c2..4750af95e5 100644 --- a/includes/templates/Usercreate.php +++ b/includes/templates/Usercreate.php @@ -158,9 +158,10 @@ class UsercreateTemplate extends BaseTemplate { 'id' => 'wpEmail', 'tabindex' => '6', 'size' => '20', + 'required' => $this->data['emailrequired'], 'placeholder' => $this->getMsg( $this->data['loggedin'] ? 'createacct-another-email-ph' : 'createacct-email-ph' )->text() - ) + ( $this->data['emailrequired'] ? array() : array( 'required' => '' ) ) ); + ) ); ?> diff --git a/includes/templates/Userlogin.php b/includes/templates/Userlogin.php index f5ae3539bf..5eb609487e 100644 --- a/includes/templates/Userlogin.php +++ b/includes/templates/Userlogin.php @@ -69,10 +69,6 @@ class UserloginTemplate extends BaseTemplate { data['name'] ) { - $extraAttrs['autofocus'] = ''; - } echo Html::input( 'wpName', $this->data['name'], 'text', array( 'class' => 'loginText', 'id' => 'wpName1', @@ -80,9 +76,11 @@ class UserloginTemplate extends BaseTemplate { 'size' => '20', // 'required' is blacklisted for now in Html.php due to browser issues. // Keeping here in case that changes. - 'required', + 'required' => true, + // Set focus to this field if it's blank. + 'autofocus' => !$this->data['name'], 'placeholder' => $this->getMsg( 'userlogin-yourname-ph' )->text() - ) + $extraAttrs ); + ) ); ?> @@ -101,18 +99,15 @@ class UserloginTemplate extends BaseTemplate { ?> data['name'] ) { - $extraAttrs['autofocus'] = ''; - } echo Html::input( 'wpPassword', null, 'password', array( 'class' => 'loginPassword', 'id' => 'wpPassword1', 'tabindex' => '2', 'size' => '20', + // Set focus to this field if username is filled in. + 'autofocus' => (bool)$this->data['name'], 'placeholder' => $this->getMsg( 'userlogin-yourpassword-ph' )->text() - ) + $extraAttrs ); + ) ); ?> -- 2.20.1