1 <?php
2 3 4 5 6 7 8 9 10
11 namespace uix\ui\control;
12
13 14 15 16 17
18 class select extends \uix\ui\control{
19
20 21 22 23 24 25 26
27 public $type = 'select';
28
29
30 31 32 33 34 35 36
37 public function classes() {
38
39 $classes = array(
40 'select-field'
41 );
42
43 return $classes;
44 }
45
46 47 48 49 50 51 52 53
54 public function input(){
55
56 $input = '<select ' . $this->build_attributes() . '>';
57
58 if( !isset( $this->struct['value'] ) )
59 $input .= '<option></option>';
60
61 $input .= $this->build_options();
62
63 $input .= '</select>';
64
65 return $input;
66 }
67
68 69 70 71 72 73 74 75
76 public function build_options(){
77 $input = '';
78 $value = $this->get_value();
79
80 if( !empty( $this->struct['choices'] ) ){
81 foreach( $this->struct['choices'] as $option_value => $option_label) {
82 $sel = null;
83 if( $option_value == $value )
84 $sel = ' selected="selected"';
85
86 $input .= '<option value="' . esc_attr( $option_value ) . '"' . $sel . '>' . esc_html( $option_label ) . '</option>';
87 }
88 }
89 return $input;
90 }
91
92 }