MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mfloatfield.class
Ir para a documentação deste ficheiro.
1<?php
2
4$MIOLO->page->addScript('m_floatfield.js');
5
29{
33 private $userField;
34
38 private $fixed = 2;
39
43 private $separator = ',';
44
56 public function __construct($name='', $value='', $label='', $size=10, $hint='', $validator=NULL, $isReadOnly=false, $fixed=2, $separator=',')
57 {
58 $userFieldId = "{$name}user";
59 $this->userField = new MTextField($userFieldId, $value, $label, $size, $hint);
60
61
62 parent::__construct($name, $value, $label, $size, $hint, $validator, $isReadOnly);
63
64 $this->fixed = $fixed;
65 $this->separator = $separator;
66 $this->hint = null;
67 }
68
72 public function setValue($value)
73 {
74 if ( isset($value) && $value != '' )
75 {
76 if ( $this->separator == ',' )
77 {
78 $userValue = str_replace('.', ',', $value);
79 }
80 }
81
82 $this->userField->setValue($userValue);
83 $this->value = $value;
84 }
85
89 public function setFixed($fixed)
90 {
91 $this->fixed = $fixed;
92 }
93
97 public function getFixed()
98 {
99 return $this->fixed;
100 }
101
105 public function setSeparator($separator)
106 {
107 $this->separator = $separator;
108 }
109
113 public function getSeparator()
114 {
115 return $this->separator;
116 }
117
124 public function addAttribute($name, $value='', $userField = true)
125 {
126 if ( $userField )
127 {
128 $this->userField->addAttribute($name, $value);
129 }
130 else
131 {
132 parent::addAttribute($name, $value);
133 }
134 }
135
142 public function addBoxStyle($name, $value)
143 {
144 parent::addBoxStyle($name, $value);
145 $this->userField->addBoxStyle($name, $value);
146 }
147
153 public function setReadOnly($readOnly)
154 {
155 parent::setReadOnly($readOnly);
156 $this->userField->setReadOnly($readOnly);
157 }
158
162 public function generate()
163 {
164 $this->setValue($this->value);
165 $this->userField->setValue($this->value);
166
167 $jsValidate = "MIOLO_FloatField.validate(this, $this->fixed, '$this->separator');";
168 $jsUpdate = "MIOLO_FloatField.update(this, '$this->name', $this->fixed, '$this->separator');";
169
170 // Remove non float
171 $this->userField->addAttribute('onkeyup', "$jsValidate $jsUpdate");
172
173 // Update real field
174 $this->userField->addAttribute('onkeypress', $jsUpdate);
175
176 // Do everything when changing the value other way (like pasting)
177 $this->userField->addAttribute('onchange', "$jsValidate $jsUpdate");
178
179 $this->addAttribute("style", "display: none", false);
180 return $this->userField->generate() . parent::generate();
181 }
182
183 public function setJsHint( $hint )
184 {
185 $this->userField->setJsHint( $hint );
186 }
187}
188
189?>
setSeparator($separator)
__construct($name='', $value='', $label='', $size=10, $hint='', $validator=NULL, $isReadOnly=false, $fixed=2, $separator=',')
addAttribute($name, $value='', $userField=true)
setValue($value)
setFixed($fixed)
setJsHint( $hint)
addBoxStyle($name, $value)
setReadOnly($readOnly)
static getInstance()
Definição miolo.class:134
$MIOLO