MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mformcontrol.class
Ir para a documentação deste ficheiro.
1<?php
2
3class MFormControl extends MControl
4{
5 public $label;
6 public $value;
7 public $hint;
8
13 public $form;
14
15 public $formName;
16 public $showLabel; // se label deve ser exibido junto com o campo
18 public $forceShowLabel = false;
19
24
29 private $addedValidator;
30
31 public $autoSetRequired = true;
32
33 public function __construct( $name, $value = '', $label = '', $color = '', $hint = '' )
34 {
35 parent::__construct( $name );
36
37 $this->addStyleFile( 'm_controls.css' );
38 $this->setValue($value);
39 $this->label = $label;
40 $this->hint = $hint;
41
42 if ( $color != '' )
43 {
44 $this->color = $color;
45 }
46
47 $this->showLabel = true;
48 $this->autoPostBack = false;
49 $this->form = NULL;
50 }
51
52
53 public function setValue( $value )
54 {
55 $this->value = $value;
56 }
57
58
59 public function getValue()
60 {
61 return $this->value;
62 }
63
64
65 public function setLabel( $label )
66 {
67 $this->label = $label;
68 }
69
70
71 public function setAutoPostBack( $value )
72 {
73 $this->autoPostBack = $value;
74 }
75
76 function setAutoSubmit( $isAuto = true )
77 {
78 $this->autoPostBack = $isAuto;
79 }
80
81 public function getIsRequired()
82 {
83 return $this->isRequired;
84 }
85
91 public function setIsRequired($isRequired)
92 {
93 $this->isRequired = $isRequired;
94
95 if ( $isRequired )
96 {
97 $this->addFieldValidator();
98 }
99
100 return $this;
101 }
102
109 public function getRequiredType()
110 {
111 return $this->getIsRequired() ? 'required' : 'optional';
112 }
113
114 private function addFieldValidator()
115 {
116 if ( $this->getFieldForm() instanceof MForm && !$this->addedValidator )
117 {
118 $this->getFieldForm()->AddValidator( new MRequiredValidator($this->name, $this->label, $this->getRequiredType()) );
119
120 $this->addedValidator = true;
121 }
122 }
123
128 public function getFieldForm()
129 {
130 return $this->form;
131 }
132
138 public function setFieldForm(MForm $form)
139 {
140 $this->form = $form;
141
142 if ( $this->getIsRequired() )
143 {
144 $this->addFieldValidator();
145 }
146 }
147
148 public function generateLabel()
149 {
150 $label = '';
151 $this->showLabel = ( $this->formMode >= MControl::FORM_MODE_SHOW_ABOVE );
152
153 if ( ( $this->showLabel ) && ( $this->label != '' ) )
154 {
155 $fieldLabel = new MFieldLabel($this->id, $this->label);
156 $fieldLabel->setClass(MControl::CLASS_CAPTION);
157
158 if( ! $this->validator && method_exists($this->form, 'getFieldValidator') )
159 {
160 $this->validator = $this->form->getFieldValidator($this->name);
161 }
162
163 $r = $this->attrs->items['required'] || ($this->validator && $this->validator->type == 'required');
164
165 if( $r && trim(MUtil::removeSpaceChars($this->label)) )
166 {
167 $fieldLabel->setClass( MControl::CLASS_CAPTION_REQUIRED );
168 }
169
170 $label = $this->painter->label( $fieldLabel );
171
172 if ( $this->formMode == MControl::FORM_MODE_SHOW_NBSP )
173 {
174 $label .= "&nbsp;&nbsp;";
175 }
176 }
177
178 return $label;
179 }
180
181}
182?>
const FORM_MODE_SHOW_NBSP
Definição mcontrol.class:44
const CLASS_CAPTION
Definição mcontrol.class:46
addStyleFile( $styleFile)
Definição mcontrol.class:412
const CLASS_CAPTION_REQUIRED
Definição mcontrol.class:47
const FORM_MODE_SHOW_ABOVE
Definição mcontrol.class:43
setIsRequired($isRequired)
setAutoSubmit( $isAuto=true)
setAutoPostBack( $value)
setLabel( $label)
setFieldForm(MForm $form)
__construct( $name, $value='', $label='', $color='', $hint='')
setValue( $value)
Definição mform.class:9
static removeSpaceChars($value)
Definição mutil.class:117