false ]; /** * @var array */ protected static $propsRule = [ 'multiple' => 'boolean', 'disabled' => 'boolean', 'clearable' => 'boolean', 'filterable' => 'boolean', 'size' => 'string', 'placeholder' => 'string', 'transfer' => 'string', 'placement' => 'string', 'notFoundText' => 'string', ]; /** * */ protected function init() { $this->placeholder($this->getPlaceHolder()); } /** * @param $value * @return $this */ public function value($value) { if ($value === null) return $this; if (!is_array($value)) $this->value[] = $value; else { foreach ($value as $v) { $this->value[] = (string)$v; } } return $this; } protected function getValidateHandler() { if($this->props['multiple'] == true) return Validate::arr(); else return Validate::str(); } /** * @return array */ public function build() { $options = []; foreach ($this->options as $option) { if ($option instanceof Option) $options[] = $option->build(); } $value = $this->value; $isArr = is_array($value); if ($this->props['multiple'] == false && $isArr) $value = isset($value[0]) ? $value[0] : ''; else if($isArr){ $value = array_unique($value); foreach ($value as $k=>$v){ $value[$k] = (string)$v; } } return [ 'type' => $this->name, 'field' => $this->field, 'title' => $this->title, 'value' => $value, 'props' => (object)$this->props, 'options' => $options, 'validate' => $this->validate, 'col'=>$this->col ]; } }