3 abstract class AphrontFormControl
extends AphrontView
{
13 private $controlStyle;
18 public function setHidden($hidden) {
19 $this->hidden
= $hidden;
23 public function setID($id) {
28 public function getID() {
32 public function setControlID($control_id) {
33 $this->controlID
= $control_id;
37 public function getControlID() {
38 return $this->controlID
;
41 public function setControlStyle($control_style) {
42 $this->controlStyle
= $control_style;
46 public function getControlStyle() {
47 return $this->controlStyle
;
50 public function setLabel($label) {
51 $this->label
= $label;
55 public function getLabel() {
59 public function setCaption($caption) {
60 $this->caption
= $caption;
64 public function getCaption() {
65 return $this->caption
;
68 public function setError($error) {
69 $this->error
= $error;
73 public function getError() {
77 public function setName($name) {
82 public function getName() {
86 public function setValue($value) {
87 $this->value
= $value;
91 public function getValue() {
95 public function isValid() {
96 if ($this->error
&& $this->error
!== true) {
100 if ($this->isRequired() && $this->isEmpty()) {
107 public function isRequired() {
108 return $this->required
;
111 public function isEmpty() {
112 return !strlen($this->getValue());
115 public function getSerializedValue() {
116 return $this->getValue();
119 public function readSerializedValue($value) {
120 $this->setValue($value);
124 public function readValueFromRequest(AphrontRequest
$request) {
125 $this->setValue($request->getStr($this->getName()));
129 public function readValueFromDictionary(array $dictionary) {
130 $this->setValue(idx($dictionary, $this->getName()));
134 public function setDisabled($disabled) {
135 $this->disabled
= $disabled;
139 public function getDisabled() {
140 return $this->disabled
;
143 abstract protected function renderInput();
144 abstract protected function getCustomControlClass();
146 protected function shouldRender() {
150 public function addClass($class) {
151 $this->classes
[] = $class;
155 final public function render() {
156 if (!$this->shouldRender()) {
160 $custom_class = $this->getCustomControlClass();
162 // If we don't have an ID yet, assign an automatic one so we can associate
163 // the label with the control. This allows assistive technologies to read
165 if (!$this->getID()) {
166 $this->setID(celerity_generate_unique_node_id());
171 array('class' => 'aphront-form-input'),
172 $this->renderInput());
175 if (strlen($this->getError())) {
176 $error = $this->getError();
177 if ($error === true) {
180 array('class' => 'aphront-form-error aphront-form-required'),
185 array('class' => 'aphront-form-error'),
190 if (strlen($this->getLabel())) {
194 'class' => 'aphront-form-label',
195 'for' => $this->getID(),
203 $custom_class .= ' aphront-form-control-nolabel';
206 if (strlen($this->getCaption())) {
207 $caption = phutil_tag(
209 array('class' => 'aphront-form-caption'),
210 $this->getCaption());
216 $classes[] = 'aphront-form-control';
217 $classes[] = 'grouped';
218 $classes[] = $custom_class;
219 if ($this->classes
) {
220 foreach ($this->classes
as $class) {
225 $style = $this->controlStyle
;
227 $style = 'display: none; '.$style;
233 'class' => implode(' ', $classes),
234 'id' => $this->controlID
,