| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Dojo
- * @subpackage Form_Element
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /** Zend_Dojo_Form_Element_TextBox */
- require_once 'Zend/Dojo/Form/Element/TextBox.php';
- /**
- * ValidationTextBox dijit
- *
- * @uses Zend_Dojo_Form_Element_TextBox
- * @package Zend_Dojo
- * @subpackage Form_Element
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- class Zend_Dojo_Form_Element_ValidationTextBox extends Zend_Dojo_Form_Element_TextBox
- {
- /**
- * Use ValidationTextBox dijit view helper
- * @var string
- */
- public $helper = 'ValidationTextBox';
- /**
- * Set invalidMessage
- *
- * @param string $message
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function setInvalidMessage($message)
- {
- $this->setDijitParam('invalidMessage', (string) $message);
- return $this;
- }
- /**
- * Retrieve invalidMessage
- *
- * @return string|null
- */
- public function getInvalidMessage()
- {
- return $this->getDijitParam('invalidMessage');
- }
- /**
- * Set promptMessage
- *
- * @param string $message
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function setPromptMessage($message)
- {
- $this->setDijitParam('promptMessage', (string) $message);
- return $this;
- }
- /**
- * Retrieve promptMessage
- *
- * @return string|null
- */
- public function getPromptMessage()
- {
- return $this->getDijitParam('promptMessage');
- }
- /**
- * Set regExp
- *
- * @param string $regexp
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function setRegExp($regexp)
- {
- $this->setDijitParam('regExp', (string) $regexp);
- return $this;
- }
- /**
- * Retrieve regExp
- *
- * @return string|null
- */
- public function getRegExp()
- {
- return $this->getDijitParam('regExp');
- }
- /**
- * Set an individual constraint
- *
- * @param string $key
- * @param mixed $value
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function setConstraint($key, $value)
- {
- $constraints = $this->getConstraints();
- $constraints[(string) $key] = $value;
- $this->setConstraints($constraints);
- return $this;
- }
- /**
- * Set validation constraints
- *
- * Refer to Dojo dijit.form.ValidationTextBox documentation for valid
- * structure.
- *
- * @param array $constraints
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function setConstraints(array $constraints)
- {
- $tmp = $this->getConstraints();
- $constraints = array_merge($tmp, $constraints);
- array_walk_recursive($constraints, array($this, '_castBoolToString'));
- $this->setDijitParam('constraints', $constraints);
- return $this;
- }
- /**
- * Is the given constraint set?
- *
- * @param string $key
- * @return bool
- */
- public function hasConstraint($key)
- {
- $constraints = $this->getConstraints();
- return array_key_exists((string)$key, $constraints);
- }
- /**
- * Get an individual constraint
- *
- * @param string $key
- * @return mixed
- */
- public function getConstraint($key)
- {
- $key = (string) $key;
- if (!$this->hasConstraint($key)) {
- return null;
- }
- return $this->dijitParams['constraints'][$key];
- }
- /**
- * Get constraints
- *
- * @return array
- */
- public function getConstraints()
- {
- if ($this->hasDijitParam('constraints')) {
- return $this->getDijitParam('constraints');
- }
- return array();
- }
- /**
- * Remove a single constraint
- *
- * @param string $key
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function removeConstraint($key)
- {
- $key = (string) $key;
- if ($this->hasConstraint($key)) {
- unset($this->dijitParams['constraints'][$key]);
- }
- return $this;
- }
- /**
- * Clear all constraints
- *
- * @return Zend_Dojo_Form_Element_ValidationTextBox
- */
- public function clearConstraints()
- {
- return $this->removeDijitParam('constraints');
- }
- /**
- * Cast a boolean value to a string
- *
- * @param mixed $item
- * @param string $key
- * @return void
- */
- protected function _castBoolToString(&$item, $key)
- {
- if (is_bool($item)) {
- $item = ($item) ? 'true' : 'false';
- }
- }
- }
|