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 $this->getValue() === null ||
!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());
174 $error = $this->error
;
175 if ($error !== null && strlen($error)) {
176 if ($error === true) {
179 array('class' => 'aphront-form-error aphront-form-required'),
184 array('class' => 'aphront-form-error'),
191 $label = $this->label
;
192 if ($label !== null && strlen($label)) {
196 'class' => 'aphront-form-label',
197 'for' => $this->getID(),
205 $custom_class .= ' aphront-form-control-nolabel';
208 $caption = $this->caption
;
209 if ($caption !== null && strlen($caption)) {
210 $caption = phutil_tag(
212 array('class' => 'aphront-form-caption'),
213 $this->getCaption());
219 $classes[] = 'aphront-form-control';
220 $classes[] = 'grouped';
221 $classes[] = $custom_class;
222 if ($this->classes
) {
223 foreach ($this->classes
as $class) {
228 $style = $this->controlStyle
;
230 $style = 'display: none; '.$style;
236 'class' => implode(' ', $classes),
237 'id' => $this->controlID
,