1 <?php
2 3 4 5 6 7 8 9 10
11 namespace uix\ui\control;
12
13 14 15 16 17
18 class radio extends \uix\ui\control{
19
20 21 22 23 24 25 26
27 public $type = 'radio';
28
29 30 31 32 33 34
35 public function set_attributes() {
36 parent::set_attributes();
37
38 $this->attributes['type'] = $this->type;
39 unset( $this->attributes['id'] );
40
41 }
42
43
44 45 46 47 48 49 50 51
52 public function input(){
53
54 $input = '';
55 $values = (array) $this->get_value();
56 $id = $this->id();
57
58 foreach ($this->struct['choices'] as $option_value => $option_label) {
59 $sel = null;
60 $option_id = $id . '-' . sanitize_key( $option_value );
61 if( in_array( $option_value, $values ) )
62 $sel = ' checked="checked"';
63
64 $input .= '<div class="uix-' . esc_attr( $this->type ) . '">';
65 $input .= '<label for="' . $option_id . '">';
66 $input .= '<input id="' . $option_id . '" ' . $this->build_attributes() . ' value="' . esc_attr( $option_value ) . '"' . $sel . '>';
67 $input .= esc_html( $option_label );
68 $input .= '</label>';
69 $input .= '</div>';
70 }
71
72 return $input;
73 }
74
75 }