data['options'][] = array( 'value' => $value, 'text' => isset($text) ? $text : $value, 'more' => $more ); return $this; } public function options(array $options) : Select{ foreach($options as $option){ if(is_string($option)){ $this->option($option); continue; } $this->data['options'][] = $option; //TODO convert to $this->option } return $this; } public function other(Input $input, string $text, string $more = ''): Select{ $input->rename($this->name()); $this->data['other'] = $input; $this->data['other.text'] = $text; $this->data['other.more'] = $more; return $this; } public function valid($data)/*: bool|string*/{ $parent = parent::valid($data); if($parent !== true || !isset($data)) return $parent; foreach($this->data['options'] as $option){ if($option['value'] == $data) return $parent; } if(isset($this->data['other'])){ $input = $this->data['other']; return $input->valid($data); } return 'incorrect'; } public function html(string $more = ''): string{ $selected = false; $options = ''; foreach($this->data['options'] as $option){ $options .= ''; } $html = ''; if(isset($this->data['other'])){ $html .= $this->data['other']->html($inputmore.$this->data['other.more']); } return $html; } }