ComboBox.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Dojo_Form_Element_DijitMulti */
  22. require_once 'Zend/Dojo/Form/Element/DijitMulti.php';
  23. /**
  24. * ComboBox dijit
  25. *
  26. * @uses Zend_Dojo_Form_Element_DijitMulti
  27. * @package Zend_Dojo
  28. * @subpackage Form_Element
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @version $Id$
  32. */
  33. class Zend_Dojo_Form_Element_ComboBox extends Zend_Dojo_Form_Element_DijitMulti
  34. {
  35. /**
  36. * Use ComboBox dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'ComboBox';
  40. /**
  41. * Flag: autoregister inArray validator?
  42. * @var bool
  43. */
  44. protected $_registerInArrayValidator = false;
  45. /**
  46. * Get datastore information
  47. *
  48. * @return array
  49. */
  50. public function getStoreInfo()
  51. {
  52. if (!$this->hasDijitParam('store')) {
  53. $this->dijitParams['store'] = array();
  54. }
  55. return $this->dijitParams['store'];
  56. }
  57. /**
  58. * Set datastore identifier
  59. *
  60. * @param string $identifier
  61. * @return Zend_Dojo_Form_Element_ComboBox
  62. */
  63. public function setStoreId($identifier)
  64. {
  65. $store = $this->getStoreInfo();
  66. $store['store'] = (string) $identifier;
  67. $this->setDijitParam('store', $store);
  68. return $this;
  69. }
  70. /**
  71. * Get datastore identifier
  72. *
  73. * @return string|null
  74. */
  75. public function getStoreId()
  76. {
  77. $store = $this->getStoreInfo();
  78. if (array_key_exists('store', $store)) {
  79. return $store['store'];
  80. }
  81. return null;
  82. }
  83. /**
  84. * Set datastore dijit type
  85. *
  86. * @param string $dojoType
  87. * @return Zend_Dojo_Form_Element_ComboBox
  88. */
  89. public function setStoreType($dojoType)
  90. {
  91. $store = $this->getStoreInfo();
  92. $store['type'] = (string) $dojoType;
  93. $this->setDijitParam('store', $store);
  94. return $this;
  95. }
  96. /**
  97. * Get datastore dijit type
  98. *
  99. * @return string|null
  100. */
  101. public function getStoreType()
  102. {
  103. $store = $this->getStoreInfo();
  104. if (array_key_exists('type', $store)) {
  105. return $store['type'];
  106. }
  107. return null;
  108. }
  109. /**
  110. * Set datastore parameters
  111. *
  112. * @param array $params
  113. * @return Zend_Dojo_Form_Element_ComboBox
  114. */
  115. public function setStoreParams(array $params)
  116. {
  117. $store = $this->getStoreInfo();
  118. $store['params'] = $params;
  119. $this->setDijitParam('store', $store);
  120. return $this;
  121. }
  122. /**
  123. * Get datastore params
  124. *
  125. * @return array
  126. */
  127. public function getStoreParams()
  128. {
  129. $store = $this->getStoreInfo();
  130. if (array_key_exists('params', $store)) {
  131. return $store['params'];
  132. }
  133. return array();
  134. }
  135. /**
  136. * Set autocomplete flag
  137. *
  138. * @param bool $flag
  139. * @return Zend_Dojo_Form_Element_ComboBox
  140. */
  141. public function setAutocomplete($flag)
  142. {
  143. $this->setDijitParam('autocomplete', (bool) $flag);
  144. return $this;
  145. }
  146. /**
  147. * Get autocomplete flag
  148. *
  149. * @return bool
  150. */
  151. public function getAutocomplete()
  152. {
  153. if (!$this->hasDijitParam('autocomplete')) {
  154. return false;
  155. }
  156. return $this->getDijitParam('autocomplete');
  157. }
  158. /**
  159. * Is the value valid?
  160. *
  161. * @param string $value
  162. * @param mixed $context
  163. * @return bool
  164. */
  165. public function isValid($value, $context = null)
  166. {
  167. $storeInfo = $this->getStoreInfo();
  168. if (!empty($storeInfo)) {
  169. $this->setRegisterInArrayValidator(false);
  170. }
  171. return parent::isValid($value, $context);
  172. }
  173. }