File indexing completed on 2025-03-02 05:29:19
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dojo 0017 * @subpackage Form_Element 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 0022 /** Zend_Dojo_Form_Element_TextBox */ 0023 // require_once 'Zend/Dojo/Form/Element/TextBox.php'; 0024 0025 /** 0026 * ValidationTextBox dijit 0027 * 0028 * @uses Zend_Dojo_Form_Element_TextBox 0029 * @package Zend_Dojo 0030 * @subpackage Form_Element 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 * @version $Id$ 0034 */ 0035 class Zend_Dojo_Form_Element_ValidationTextBox extends Zend_Dojo_Form_Element_TextBox 0036 { 0037 /** 0038 * Use ValidationTextBox dijit view helper 0039 * @var string 0040 */ 0041 public $helper = 'ValidationTextBox'; 0042 0043 /** 0044 * Set invalidMessage 0045 * 0046 * @param string $message 0047 * @return Zend_Dojo_Form_Element_ValidationTextBox 0048 */ 0049 public function setInvalidMessage($message) 0050 { 0051 $this->setDijitParam('invalidMessage', (string) $message); 0052 return $this; 0053 } 0054 0055 /** 0056 * Retrieve invalidMessage 0057 * 0058 * @return string|null 0059 */ 0060 public function getInvalidMessage() 0061 { 0062 return $this->getDijitParam('invalidMessage'); 0063 } 0064 0065 /** 0066 * Set promptMessage 0067 * 0068 * @param string $message 0069 * @return Zend_Dojo_Form_Element_ValidationTextBox 0070 */ 0071 public function setPromptMessage($message) 0072 { 0073 $this->setDijitParam('promptMessage', (string) $message); 0074 return $this; 0075 } 0076 0077 /** 0078 * Retrieve promptMessage 0079 * 0080 * @return string|null 0081 */ 0082 public function getPromptMessage() 0083 { 0084 return $this->getDijitParam('promptMessage'); 0085 } 0086 0087 /** 0088 * Set regExp 0089 * 0090 * @param string $regexp 0091 * @return Zend_Dojo_Form_Element_ValidationTextBox 0092 */ 0093 public function setRegExp($regexp) 0094 { 0095 $this->setDijitParam('regExp', (string) $regexp); 0096 return $this; 0097 } 0098 0099 /** 0100 * Retrieve regExp 0101 * 0102 * @return string|null 0103 */ 0104 public function getRegExp() 0105 { 0106 return $this->getDijitParam('regExp'); 0107 } 0108 0109 /** 0110 * Set an individual constraint 0111 * 0112 * @param string $key 0113 * @param mixed $value 0114 * @return Zend_Dojo_Form_Element_ValidationTextBox 0115 */ 0116 public function setConstraint($key, $value) 0117 { 0118 $constraints = $this->getConstraints(); 0119 $constraints[(string) $key] = $value; 0120 $this->setConstraints($constraints); 0121 return $this; 0122 } 0123 0124 /** 0125 * Set validation constraints 0126 * 0127 * Refer to Dojo dijit.form.ValidationTextBox documentation for valid 0128 * structure. 0129 * 0130 * @param array $constraints 0131 * @return Zend_Dojo_Form_Element_ValidationTextBox 0132 */ 0133 public function setConstraints(array $constraints) 0134 { 0135 $tmp = $this->getConstraints(); 0136 $constraints = array_merge($tmp, $constraints); 0137 array_walk_recursive($constraints, array($this, '_castBoolToString')); 0138 $this->setDijitParam('constraints', $constraints); 0139 return $this; 0140 } 0141 0142 /** 0143 * Is the given constraint set? 0144 * 0145 * @param string $key 0146 * @return bool 0147 */ 0148 public function hasConstraint($key) 0149 { 0150 $constraints = $this->getConstraints(); 0151 return array_key_exists((string)$key, $constraints); 0152 } 0153 0154 /** 0155 * Get an individual constraint 0156 * 0157 * @param string $key 0158 * @return mixed 0159 */ 0160 public function getConstraint($key) 0161 { 0162 $key = (string) $key; 0163 if (!$this->hasConstraint($key)) { 0164 return null; 0165 } 0166 return $this->dijitParams['constraints'][$key]; 0167 } 0168 0169 /** 0170 * Get constraints 0171 * 0172 * @return array 0173 */ 0174 public function getConstraints() 0175 { 0176 if ($this->hasDijitParam('constraints')) { 0177 return $this->getDijitParam('constraints'); 0178 } 0179 return array(); 0180 } 0181 0182 /** 0183 * Remove a single constraint 0184 * 0185 * @param string $key 0186 * @return Zend_Dojo_Form_Element_ValidationTextBox 0187 */ 0188 public function removeConstraint($key) 0189 { 0190 $key = (string) $key; 0191 if ($this->hasConstraint($key)) { 0192 unset($this->dijitParams['constraints'][$key]); 0193 } 0194 return $this; 0195 } 0196 0197 /** 0198 * Clear all constraints 0199 * 0200 * @return Zend_Dojo_Form_Element_ValidationTextBox 0201 */ 0202 public function clearConstraints() 0203 { 0204 return $this->removeDijitParam('constraints'); 0205 } 0206 0207 /** 0208 * Cast a boolean value to a string 0209 * 0210 * @param mixed $item 0211 * @param string $key 0212 * @return void 0213 */ 0214 protected function _castBoolToString(&$item, $key) 0215 { 0216 if (is_bool($item)) { 0217 $item = ($item) ? 'true' : 'false'; 0218 } 0219 } 0220 }