From 586296b3d19269b606bc017d5de25c86cca63bfe Mon Sep 17 00:00:00 2001 From: mainframe98 Date: Sat, 19 Jul 2025 10:02:33 +0200 Subject: [PATCH] Support specifying form fields as readonly Summary: Similar to AphrontFormTextAreaControl. I went with manually specifying the property in each class, as there are only 5 (AphrontFormTextControl is handled in D26195) and other types of inputs do not support the readonly property. Ref T16177 Test Plan: Compare against AphrontFormTextAreaControl. If feeling adventurous, maybe change one of the callers of the input fields to readonly. Reviewers: O1 Blessed Committers, valerio.bozzolan, aklapper Reviewed By: O1 Blessed Committers, valerio.bozzolan, aklapper Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T16177 Differential Revision: https://we.phorge.it/D26200 --- .../control/AphrontFormTextWithSubmitControl.php | 11 +++++++++++ .../form/control/AphrontFormTypeaheadControl.php | 11 +++++++++++ .../form/control/PHUIFormFreeformDateControl.php | 12 ++++++++++++ src/view/form/control/PHUIFormNumberControl.php | 11 +++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/view/form/control/AphrontFormTextWithSubmitControl.php b/src/view/form/control/AphrontFormTextWithSubmitControl.php index 07b872d1fe..ed33f3ce82 100644 --- a/src/view/form/control/AphrontFormTextWithSubmitControl.php +++ b/src/view/form/control/AphrontFormTextWithSubmitControl.php @@ -3,6 +3,7 @@ final class AphrontFormTextWithSubmitControl extends AphrontFormControl { private $submitLabel; + private $readOnly; public function setSubmitLabel($submit_label) { $this->submitLabel = $submit_label; @@ -13,6 +14,15 @@ final class AphrontFormTextWithSubmitControl extends AphrontFormControl { return $this->submitLabel; } + public function setReadOnly($read_only) { + $this->readOnly = $read_only; + return $this; + } + + protected function getReadOnly() { + return $this->readOnly; + } + protected function getCustomControlClass() { return 'aphront-form-control-text-with-submit'; } @@ -37,6 +47,7 @@ final class AphrontFormTextWithSubmitControl extends AphrontFormControl { 'name' => $this->getName(), 'value' => $this->getValue(), 'disabled' => $this->getDisabled() ? 'disabled' : null, + 'readonly' => $this->getReadOnly() ? 'readonly' : null, 'id' => $this->getID(), ))), phutil_tag( diff --git a/src/view/form/control/AphrontFormTypeaheadControl.php b/src/view/form/control/AphrontFormTypeaheadControl.php index 1e859ee132..31360d5feb 100644 --- a/src/view/form/control/AphrontFormTypeaheadControl.php +++ b/src/view/form/control/AphrontFormTypeaheadControl.php @@ -4,6 +4,7 @@ final class AphrontFormTypeaheadControl extends AphrontFormControl { private $hardpointID; private $placeholder; + private $readonly; public function setHardpointID($hardpoint_id) { $this->hardpointID = $hardpoint_id; @@ -19,6 +20,15 @@ final class AphrontFormTypeaheadControl extends AphrontFormControl { return $this; } + public function setReadOnly($read_only) { + $this->readOnly = $read_only; + return $this; + } + + protected function getReadOnly() { + return $this->readOnly; + } + protected function getCustomControlClass() { return 'aphront-form-control-typeahead'; } @@ -38,6 +48,7 @@ final class AphrontFormTypeaheadControl extends AphrontFormControl { 'value' => $this->getValue(), 'placeholder' => $this->placeholder, 'disabled' => $this->getDisabled() ? 'disabled' : null, + 'readonly' => $this->getReadOnly() ? 'readonly' : null, 'autocomplete' => 'off', 'id' => $this->getID(), ))); diff --git a/src/view/form/control/PHUIFormFreeformDateControl.php b/src/view/form/control/PHUIFormFreeformDateControl.php index 74a32d2e0a..daf228226d 100644 --- a/src/view/form/control/PHUIFormFreeformDateControl.php +++ b/src/view/form/control/PHUIFormFreeformDateControl.php @@ -2,6 +2,17 @@ final class PHUIFormFreeformDateControl extends AphrontFormControl { + private $readOnly; + + public function setReadOnly($read_only) { + $this->readOnly = $read_only; + return $this; + } + + protected function getReadOnly() { + return $this->readOnly; + } + protected function getCustomControlClass() { return 'aphront-form-control-text'; } @@ -14,6 +25,7 @@ final class PHUIFormFreeformDateControl extends AphrontFormControl { 'name' => $this->getName(), 'value' => $this->getValue(), 'disabled' => $this->getDisabled() ? 'disabled' : null, + 'readonly' => $this->getReadOnly() ? 'readonly' : null, 'id' => $this->getID(), )); } diff --git a/src/view/form/control/PHUIFormNumberControl.php b/src/view/form/control/PHUIFormNumberControl.php index c577bebbd0..7f976f2546 100644 --- a/src/view/form/control/PHUIFormNumberControl.php +++ b/src/view/form/control/PHUIFormNumberControl.php @@ -4,6 +4,7 @@ final class PHUIFormNumberControl extends AphrontFormControl { private $disableAutocomplete; private $autofocus; + private $readOnly; public function setDisableAutocomplete($disable_autocomplete) { $this->disableAutocomplete = $disable_autocomplete; @@ -23,6 +24,15 @@ final class PHUIFormNumberControl extends AphrontFormControl { return $this->autofocus; } + public function setReadOnly($read_only) { + $this->readOnly = $read_only; + return $this; + } + + protected function getReadOnly() { + return $this->readOnly; + } + protected function getCustomControlClass() { return 'phui-form-number'; } @@ -42,6 +52,7 @@ final class PHUIFormNumberControl extends AphrontFormControl { 'name' => $this->getName(), 'value' => $this->getValue(), 'disabled' => $this->getDisabled() ? 'disabled' : null, + 'readonly' => $this->getReadOnly() ? 'readonly' : null, 'autocomplete' => $autocomplete, 'id' => $this->getID(), 'autofocus' => ($this->getAutofocus() ? 'autofocus' : null), -- 2.51.2