| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\forms;
- use MGModule\DNSManager2 as main;
- /**
- * Select Form Field
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class selectField extends abstractField{
- public $translateOptions = true;
- public $addValueIfNotExits = false;
- public $options;
- public $select2 = false;
- public $multiple;
-
- function prepare() {
- if($this->select2)
- {
- $this->type = 'select2';
- if(empty($this->addIDs))
- {
- $this->addIDs = 'RandID'.rand(0,100);
- }
- }
- else
- {
- $this->type = 'select';
- }
-
- if(array_keys($this->options) == range(0, count($this->options) - 1))
- {
- $options = array();
- foreach($this->options as $value)
- {
- $options[$value] = $value;
- }
- $this->options = $options;
- }
- else
- {
- $this->translateOptions = false;
- }
-
- if($this->addValueIfNotExits)
- {
- if($this->value && !isset($this->options[$this->value]))
- {
- $this->options[$this->value] = $this->value;
- }
- }
-
- if($this->translateOptions)
- {
- if(!is_array($this->options))throw new main\mgLibs\exceptions\system('Invalid Fields Options');
- $options = array();
- foreach($this->options as $value)
- {
- $options[$value] = main\mgLibs\lang::T($this->formName,$this->name,'options',$value);
- }
- $this->options = $options;
- }
- }
- }
|