UIX Documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • None
  • uix
    • data
    • ui
      • control

Classes

  • uix\data\data
  • uix\ui
  • uix\ui\box
  • uix\ui\control
  • uix\ui\control\autocomplete
  • uix\ui\control\button
  • uix\ui\control\checkbox
  • uix\ui\control\color
  • uix\ui\control\editor
  • uix\ui\control\email
  • uix\ui\control\file
  • uix\ui\control\hidden
  • uix\ui\control\number
  • uix\ui\control\post_relation
  • uix\ui\control\radio
  • uix\ui\control\select
  • uix\ui\control\separator
  • uix\ui\control\slider
  • uix\ui\control\template
  • uix\ui\control\text
  • uix\ui\control\textarea
  • uix\ui\control\toggle
  • uix\ui\footer
  • uix\ui\grid
  • uix\ui\header
  • uix\ui\help
  • uix\ui\metabox
  • uix\ui\modal
  • uix\ui\notice
  • uix\ui\page
  • uix\ui\panel
  • uix\ui\post_type
  • uix\ui\repeat
  • uix\ui\section
  • uix\ui\uix

Interfaces

  • uix\data\load
  • uix\data\save

Functions

  • uix
  • uix_autoload_class
 1 <?php
 2 /**
 3  * UIX Controls
 4  *
 5  * @package   controls
 6  * @author    David Cramer
 7  * @license   GPL-2.0+
 8  * @link
 9  * @copyright 2016 David Cramer
10  */
11 namespace uix\ui\control;
12 
13 /**
14  * Dropdown select
15  *
16  * @since 1.0.0
17  */
18 class select extends \uix\ui\control{
19 
20     /**
21      * The type of object
22      *
23      * @since       1.0.0
24      * @access public
25      * @var         string
26      */
27     public $type = 'select';
28 
29 
30     /**
31      * Gets the classes for the control input
32      *
33      * @since  1.0.0
34      * @access public
35      * @return array
36      */
37     public function classes() {
38 
39         $classes = array( 
40             'select-field'
41         );
42         
43         return $classes;
44     }
45 
46     /**
47      * Returns the main input field for rendering
48      *
49      * @since 1.0.0
50      * @see \uix\ui\uix
51      * @access public
52      * @return string 
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      * Builds the set of options to select
70      *
71      * @since 1.0.0
72      * @see \uix\ui\uix
73      * @access public
74      * @return string
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 }
UIX Documentation API documentation generated by ApiGen