web/Zend/Dojo/Form/Element/ComboBox.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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_DijitMulti */
       
    23 require_once 'Zend/Dojo/Form/Element/DijitMulti.php';
       
    24 
       
    25 /**
       
    26  * ComboBox dijit
       
    27  *
       
    28  * @uses       Zend_Dojo_Form_Element_DijitMulti
       
    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: ComboBox.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    34  */
       
    35 class Zend_Dojo_Form_Element_ComboBox extends Zend_Dojo_Form_Element_DijitMulti
       
    36 {
       
    37     /**
       
    38      * Use ComboBox dijit view helper
       
    39      * @var string
       
    40      */
       
    41     public $helper = 'ComboBox';
       
    42 
       
    43     /**
       
    44      * Flag: autoregister inArray validator?
       
    45      * @var bool
       
    46      */
       
    47     protected $_registerInArrayValidator = false;
       
    48 
       
    49     /**
       
    50      * Get datastore information
       
    51      *
       
    52      * @return array
       
    53      */
       
    54     public function getStoreInfo()
       
    55     {
       
    56         if (!$this->hasDijitParam('store')) {
       
    57             $this->dijitParams['store'] = array();
       
    58         }
       
    59         return $this->dijitParams['store'];
       
    60     }
       
    61 
       
    62     /**
       
    63      * Set datastore identifier
       
    64      *
       
    65      * @param  string $identifier
       
    66      * @return Zend_Dojo_Form_Element_ComboBox
       
    67      */
       
    68     public function setStoreId($identifier)
       
    69     {
       
    70         $store = $this->getStoreInfo();
       
    71         $store['store'] = (string) $identifier;
       
    72         $this->setDijitParam('store', $store);
       
    73         return $this;
       
    74     }
       
    75 
       
    76     /**
       
    77      * Get datastore identifier
       
    78      *
       
    79      * @return string|null
       
    80      */
       
    81     public function getStoreId()
       
    82     {
       
    83         $store = $this->getStoreInfo();
       
    84         if (array_key_exists('store', $store)) {
       
    85             return $store['store'];
       
    86         }
       
    87         return null;
       
    88     }
       
    89 
       
    90     /**
       
    91      * Set datastore dijit type
       
    92      *
       
    93      * @param  string $dojoType
       
    94      * @return Zend_Dojo_Form_Element_ComboBox
       
    95      */
       
    96     public function setStoreType($dojoType)
       
    97     {
       
    98         $store = $this->getStoreInfo();
       
    99         $store['type'] = (string) $dojoType;
       
   100         $this->setDijitParam('store', $store);
       
   101         return $this;
       
   102     }
       
   103 
       
   104     /**
       
   105      * Get datastore dijit type
       
   106      *
       
   107      * @return string|null
       
   108      */
       
   109     public function getStoreType()
       
   110     {
       
   111         $store = $this->getStoreInfo();
       
   112         if (array_key_exists('type', $store)) {
       
   113             return $store['type'];
       
   114         }
       
   115         return null;
       
   116     }
       
   117 
       
   118     /**
       
   119      * Set datastore parameters
       
   120      *
       
   121      * @param  array $params
       
   122      * @return Zend_Dojo_Form_Element_ComboBox
       
   123      */
       
   124     public function setStoreParams(array $params)
       
   125     {
       
   126         $store = $this->getStoreInfo();
       
   127         $store['params'] = $params;
       
   128         $this->setDijitParam('store', $store);
       
   129         return $this;
       
   130     }
       
   131 
       
   132     /**
       
   133      * Get datastore params
       
   134      *
       
   135      * @return array
       
   136      */
       
   137     public function getStoreParams()
       
   138     {
       
   139         $store = $this->getStoreInfo();
       
   140         if (array_key_exists('params', $store)) {
       
   141             return $store['params'];
       
   142         }
       
   143         return array();
       
   144     }
       
   145 
       
   146     /**
       
   147      * Set autocomplete flag
       
   148      *
       
   149      * @param  bool $flag
       
   150      * @return Zend_Dojo_Form_Element_ComboBox
       
   151      */
       
   152     public function setAutocomplete($flag)
       
   153     {
       
   154         $this->setDijitParam('autocomplete', (bool) $flag);
       
   155         return $this;
       
   156     }
       
   157 
       
   158     /**
       
   159      * Get autocomplete flag
       
   160      *
       
   161      * @return bool
       
   162      */
       
   163     public function getAutocomplete()
       
   164     {
       
   165         if (!$this->hasDijitParam('autocomplete')) {
       
   166             return false;
       
   167         }
       
   168         return $this->getDijitParam('autocomplete');
       
   169     }
       
   170 
       
   171     /**
       
   172      * Is the value valid?
       
   173      *
       
   174      * @param  string $value
       
   175      * @param  mixed $context
       
   176      * @return bool
       
   177      */
       
   178     public function isValid($value, $context = null)
       
   179     {
       
   180         $storeInfo = $this->getStoreInfo();
       
   181         if (!empty($storeInfo)) {
       
   182             $this->setRegisterInArrayValidator(false);
       
   183         }
       
   184         return parent::isValid($value, $context);
       
   185     }
       
   186 }