|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Dojo |
|
17 * @subpackage Form_Element |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 */ |
|
21 |
|
22 /** Zend_Dojo_Form_Element_ValidationTextBox */ |
|
23 require_once 'Zend/Dojo/Form/Element/ValidationTextBox.php'; |
|
24 |
|
25 /** |
|
26 * NumberTextBox dijit |
|
27 * |
|
28 * @uses Zend_Dojo_Form_Element_ValidationTextBox |
|
29 * @package Zend_Dojo |
|
30 * @subpackage Form_Element |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 * @version $Id: NumberTextBox.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
34 */ |
|
35 class Zend_Dojo_Form_Element_NumberTextBox extends Zend_Dojo_Form_Element_ValidationTextBox |
|
36 { |
|
37 /** |
|
38 * Use NumberTextBox dijit view helper |
|
39 * @var string |
|
40 */ |
|
41 public $helper = 'NumberTextBox'; |
|
42 |
|
43 /** |
|
44 * Allowed numeric type formats |
|
45 * @var array |
|
46 */ |
|
47 protected $_allowedTypes = array( |
|
48 'decimal', |
|
49 'scientific', |
|
50 'percent', |
|
51 'currency', |
|
52 ); |
|
53 |
|
54 /** |
|
55 * Set locale |
|
56 * |
|
57 * @param string $locale |
|
58 * @return Zend_Dojo_Form_Element_NumberTextBox |
|
59 */ |
|
60 public function setLocale($locale) |
|
61 { |
|
62 $this->setConstraint('locale', (string) $locale); |
|
63 return $this; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Retrieve locale |
|
68 * |
|
69 * @return string|null |
|
70 */ |
|
71 public function getLocale() |
|
72 { |
|
73 return $this->getConstraint('locale'); |
|
74 } |
|
75 |
|
76 /** |
|
77 * Set numeric format pattern |
|
78 * |
|
79 * @param string $pattern |
|
80 * @return Zend_Dojo_Form_Element_NumberTextBox |
|
81 */ |
|
82 public function setPattern($pattern) |
|
83 { |
|
84 $this->setConstraint('pattern', (string) $pattern); |
|
85 return $this; |
|
86 } |
|
87 |
|
88 /** |
|
89 * Retrieve numeric format pattern |
|
90 * |
|
91 * @return string|null |
|
92 */ |
|
93 public function getPattern() |
|
94 { |
|
95 return $this->getConstraint('pattern'); |
|
96 } |
|
97 |
|
98 /** |
|
99 * Set numeric format type |
|
100 * |
|
101 * @see $_allowedTypes |
|
102 * @param string $type |
|
103 * @return Zend_Dojo_Form_Element_NumberTextBox |
|
104 */ |
|
105 public function setType($type) |
|
106 { |
|
107 $type = strtolower($type); |
|
108 if (!in_array($type, $this->_allowedTypes)) { |
|
109 require_once 'Zend/Form/Element/Exception.php'; |
|
110 throw new Zend_Form_Element_Exception(sprintf('Invalid numeric type "%s" specified', $type)); |
|
111 } |
|
112 |
|
113 $this->setConstraint('type', $type); |
|
114 return $this; |
|
115 } |
|
116 |
|
117 /** |
|
118 * Retrieve type |
|
119 * |
|
120 * @return string|null |
|
121 */ |
|
122 public function getType() |
|
123 { |
|
124 return $this->getConstraint('type'); |
|
125 } |
|
126 |
|
127 /** |
|
128 * Set decimal places |
|
129 * |
|
130 * @param int $places |
|
131 * @return Zend_Dojo_Form_Element_NumberTextBox |
|
132 */ |
|
133 public function setPlaces($places) |
|
134 { |
|
135 $this->setConstraint('places', (int) $places); |
|
136 return $this; |
|
137 } |
|
138 |
|
139 /** |
|
140 * Retrieve decimal places |
|
141 * |
|
142 * @return int|null |
|
143 */ |
|
144 public function getPlaces() |
|
145 { |
|
146 return $this->getConstraint('places'); |
|
147 } |
|
148 |
|
149 /** |
|
150 * Set strict flag |
|
151 * |
|
152 * @param bool $strict |
|
153 * @return Zend_Dojo_Form_Element_NumberTextBox |
|
154 */ |
|
155 public function setStrict($flag) |
|
156 { |
|
157 $this->setConstraint('strict', (bool) $flag); |
|
158 return $this; |
|
159 } |
|
160 |
|
161 /** |
|
162 * Retrieve strict flag |
|
163 * |
|
164 * @return bool |
|
165 */ |
|
166 public function getStrict() |
|
167 { |
|
168 if (!$this->hasConstraint('strict')) { |
|
169 return false; |
|
170 } |
|
171 return ('true' == $this->getConstraint('strict')); |
|
172 } |
|
173 } |