Make a select input.

@param array  $config
@param string $selected
@param mixed $custom

@return string
170183
public function makeSelected($config, $selected, $custom)
    {
        $options = $prefix = $suffix = '';

        if (isset($config['config']['multiple'])) {
            $custom = 'multiple';
            $config['name'] = $config['name'].'[]';
        }

        if (config('form-maker.form.orientation') === 'horizontal') {
            $prefix = '<div class="'.config('form-maker.form.input-column').'">';
            $suffix = '</div>';
        }

        foreach ($config['config']['options'] as $key => $value) {
            $selectedValue = '';

            if (isset($config['config']['multiple']) && is_object($selected)) {
                if (in_array($value, $selected->toArray())) {
                    $selectedValue = 'selected';
                }
            } else {
                if ($selected == '') {
                    $selectedValue = ((string) $config['objectValue'] === (string) $value) ? 'selected' : '';
                } else {
                    if (isset($config['objectValue']) && is_array(json_decode($config['objectValue']))) {
                        $selectedValue = (in_array($value, json_decode($config['objectValue']))) ? 'selected' : '';
                    } else {
                        $selectedValue = ((string) $selected === (string) $value) ? 'selected' : '';
                    }
                }
            }

            $options .= '<option value="'.$value.'" '.$selectedValue.'>'.$key.'</option>';
        }

        return $prefix.'<select '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'">'.$options.'</select>'.$suffix;
    }
820270
public function radiolist($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'options' 	=> array(),
            'legend'    => null,
            'name'   	=> 'id',
            'selected'	=> null,
            'translate'	=> false,
            'attribs'	=> array(),
        ));

        $translator = $this->getObject('translator');
        $attribs    = $this->buildAttributes($config->attribs);

        $html   = array();
        $html[] = '<fieldset  name="'. $config->name .'" '. $attribs .'>';

        if(isset($config->legend)) {
            $html[] = '<legend>'.$config->translate ? $translator->translate( $config->legend ) : $config->legend.'</legend>';
        }

        foreach($config->options as $option)
        {
            $value = $option->value;
            $label = $config->translate ? $translator->translate( $option->label ) : $option->label;

            $extra = ($value == $config->selected ? 'checked="checked"' : '');

            if(isset($option->disabled) && $option->disabled) {
                $extra .= 'disabled="disabled"';
            }

            if(isset($option->attribs)) {
                $attribs = $this->buildAttributes($option->attribs);
            }

            $html[] = '<label class="radio" for="'.$config->name.$option->id.'">';
            $html[] = '<input type="radio" name="'.$config->name.'" id="'.$config->name.$option->id.'" value="'.$value.'" '.$extra.' '.$attribs.' />';
            $html[] = $label;
            $html[] = '</label>';
        }

        $html[] = '</fieldset>';

        return implode(PHP_EOL, $html);
    }
829699
protected function createSelectElement($options, $selected, $_attributes, &$return)
    {
        $return = '<select'.$this->attributes($_attributes).'>';

        if( is_array($options) ) foreach( $options as $key => $value )
        {
            if( is_array($selected) )
            {
                if( in_array($key, $selected) )
                {
                    $select = ' selected="selected"';
                }
                else
                {
                    $select = "";
                }
            }
            else
            {
                if( $selected == $key )
                {
                    $select = ' selected="selected"';
                }
                else
                {
                    $select = "";
                }
            }

            $return .= '<option value="'.$key.'"'.$select.'>'.$value.'</option>'.EOL;
        }

        $return .= '</select>'.EOL;
    }
22265
public function createOptions(array $options, $selected = null)
    {
        foreach ($options as $label => $value) {
            $option = $this->createOption($label, $value);

            if (is_array($selected) && in_array($value, $selected)) {
                $option->selected();
            } elseif ($selected === $value) {
                $option->selected();
            }
        }

        return $this;
    }
510260
protected function getChoiceBySelection($selection)
    {
        preg_match('/^[^(]+\(([^\)]+)\)$/', $selection, $matches);
        if (count($matches) < 2) {
            return;
        }
        $username = $matches[1];
        foreach ($this->choices as $item) {
            if ($item->getUsername() === $username) {
                return $item;
            }
        }

        return;
    }
832077
protected function addElement_select ($name, $label, $customElementConfig=array())
    {
        $defaultElementConfig = array(
            'name'       => $name,
            'attributes' => array(
                'id'         => $name,
            ),
            'options'    => array(
                'label'      => $label,
            ),
        );
        $elementConfig = array_replace_recursive(
            $defaultElementConfig,
            $customElementConfig
        );

        $this->addElement_select_configArray($elementConfig);
    }
1153827
function getSelectedValue(customSelect) {
    var hiddenSelect = this.UI.getHiddenSelect(customSelect);
    if (this.isMultiple(customSelect)) {
      var selectedOptions = [];
      [].forEach.call(hiddenSelect.options, function (option) {
        if (option.selected) {
          selectedOptions.push(option.value);
        }
      });
      return selectedOptions;
    } else {
      return hiddenSelect.options[hiddenSelect.selectedIndex].value;
    }
  }
51378
public function plainSelect($name, $list = array(), $selected = null, array $selectAttributes = [], array $optionsAttributes = [])
    {
        return parent::select($name, $list, $selected, $selectAttributes, $optionsAttributes);
    }
1110597
public static function select(string $name = '', array $values = [], array $selected = [],
                                  array $attributes = []): string
    {
        $defaultAttributes = ['method-get' => false, 'class' => 'form-select'];
        $userAttributes = \array_merge($defaultAttributes, $attributes);
        $attributes = [];
        $attributes['name'] = $userAttributes['method-get'] === false ? \sprintf('MFVARS[%s]', $name) : $name;
        $attributes['id'] = isset($userAttributes['id']) ? $userAttributes['id'] : $name;
        $attributes['data-selected'] = \implode(',', $selected);
        $wrapperClass = ['select-wrapper'];

        if (\array_key_exists('multiple', $userAttributes) && $userAttributes['multiple'] === true) {
            $attributes['multiple'] = 'multiple';
            $attributes['name'] = \sprintf('%s[]', $attributes['name']);
            $wrapperClass[] = 'multiple';
        }
        if (\array_key_exists('wrapper-class', $userAttributes)) {
            $wrapperClass[] = $userAttributes['wrapper-class'];
        }
        if (\array_key_exists('disabled', $userAttributes)) {
            $wrapperClass[] = 'disabled';
        }
        $clearAttributes = ['method-get', 'id', 'multiple', 'wrapper-class'];
        $userAttributes = static::clearAttributes($userAttributes, $clearAttributes);
        $select = Tags::select(self::getOptions($values, $selected, 0), \array_merge($attributes, $userAttributes));

        return Tags::div($select, ['class' => \implode(' ', $wrapperClass)]);
    }
1362162
protected function _checkNoSelected(array $options, array $selected, $isMultiply = false)
    {
        if ($isMultiply === 'multiple') {
            return array($options, $selected);
        }

        $_selected = array_pop($selected);

        if (!Arr::key($_selected, $options) && !empty($selected)) {
            $options = array_merge(array($_selected => $this->_translate('--No selected--')), $options);
        }

        return array($options, array($_selected));
    }
1013635
private function getOptionsElement(DOMDocument $config, $option, array $properties)
    {
        if (is_a($option, Option::class) || Option::isValid($option)) {
            $options = $config->createElementNS(self::LTICM, 'lticm:options');
            $options->setAttribute('name', $option);

            /* inherit link text and launch URL properties if not specified */
            if (!array_key_exists('text', $properties)) {
                $properties['text'] = $this->name;
            }
            if (!array_key_exists('url', $properties)) {
                $properties['url'] = $this->launchURL;
            }

            foreach ($properties as $name => $value) {
                $property = $config->createElementNS(
                    self::LTICM,
                    'lticm:property',
                    $value
                );
                $property->setAttribute('name', $name);
                $options->appendChild($property);
            }

            return $options;
        }
        return null;
    }
384393
public function modal($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'debug'    => \Kodekit::getInstance()->isDebug(),
            'selector' => '[data-k-modal]',
            'data'     => 'k-modal',
            'options_callback' => null,
            'options'  => array('type' => 'image')
        ));

        $html = '';

        if(!static::isLoaded('modal'))
        {
            $html .= $this->jquery();
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.magnific-popup.js" />';

            static::setLoaded('modal');
        }

        if(!static::isLoaded('modal-select2-fix'))
        {
            $html .= "<script>

                // WORKAROUND FOR ISSUE: #873

                kQuery(function($)
                {
                    $.magnificPopup.instance._onFocusIn = function(e)
                    {
                        // Do nothing if target element is select2 input
                        if( $(e.target).hasClass('select2-search__field') ) {
                            return true;
                        }
            
                        // Else call parent method
                        $.magnificPopup.proto._onFocusIn.call(this,e);
                    };
                });
            </script>";

            static::setLoaded('modal-select2-fix');
        }

        $options   = (string)$config->options;
        $signature = md5('modal-'.$config->selector.$config->options_callback.$options);

        if (!static::isLoaded($signature))
        {
            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= "<script>
            kQuery(function($){
                $('$config->selector').each(function(idx, el) {
                    var el = $(el);
                    var data = el.data('$config->data');
                    var options = ".$options.";
                    if (data) {
                        $.extend(true, options, data);
                    }
                    el.magnificPopup(options);
                });
            });
            </script>";

            static::setLoaded($signature);
        }

        return $html;
    }
1195599
protected function generateSelect($options, $currentValue = null)
    {
        $value = is_null($currentValue) ? $options['value'] : $currentValue;

        unset($options["type"]);
        unset($options["value"]);

        $optionsHtml = "";
        if (array_key_exists("choices", $options) && is_array($options["choices"])) {
            foreach ($options["choices"] as $key => $val) {
                $optionsHtml .= sprintf('<option%s value="%s">%s</option>', "$key" === "$value" ? ' selected="selected"' : '', $key, $val);
            }
            unset($options["choices"]);
        }

        return sprintf('<select %s>%s</select>', $this->arrayToHtmlAttributes($options), $optionsHtml);
    }
299484
public function searchableContent(array $config = array())
    {
        $result = '';
        $type = $this->searchType();

        /*
         * Plain Bootstrap with glyphicons
         */
        if ('resource-table::bootstrap' === $this->_viewName) {
            switch ($type) {

                // Select
                case 'select':
                    if (!count($this->options())) {
                        // Options must be provided for select
                        return '';
                    }
                    $result .= '<select name="resource_table_'.$this->index().'" class="'.array_get($config, 'control_class', 'form-control input-sm').' resource-table-column-filter">'.$this->_optionsHTML().'</select>';
                    break;

                // Simple string input
                case 'string':
                default:
                    $result .= '<input type="text" placeholder="'.array_get($config, 'placeholder', trans('resource-table::default.Search_for').' '.$this->label()).'" class="'.array_get($config, 'control_class', 'form-control input-sm').' resource-table-column-filter" name="resource_table_'.$this->index().'" value="'.ResourceTable::getSearchValue($this->index()).'" />';
                    break;
            }
        }

        /*
         * Just simple table
         */
        if (!$result) {
            switch ($type) {

                // Select
                case 'select':
                    if (!count($this->options())) {
                        // Options must be provided for select
                        return '';
                    }
                    $result .= '<select name="resource_table_'.$this->index().'" class="'.array_get($config, 'control_class').' resource-table-column-filter">'.$this->_optionsHTML().'</select>';
                    break;

                // Simple string input
                case 'string':
                default:
                    $result .= '<input type="text" class="'.array_get($config, 'control_class').' resource-table-column-filter" name="resource_table_'.$this->index().'" value="'.ResourceTable::getSearchValue($this->index()).'" placeholder="'.array_get($config, 'placeholder').'" />';
                    break;
            }
        }

        return $result;
    }
621219
public static function form_select($name = '', $options = array(), $selected = array(), $extra = '')
    {
        if (! is_array($selected)) {
            $selected = array($selected);
        }

        // If no selected state was submitted we will attempt to set it automatically
        if (count($selected) === 0) {
            // If the form name appears in the $_POST array we have a winner!
            if (isset($_POST[$name])) {
                $selected = array($_POST[$name]);
            }
        }

        if ($extra != '') {
            $extra = ' '.$extra;
        }

        $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';

        $form = '<select name="'.$name.'" id="'.$name.'"'. $extra.$multiple .">\n";

        foreach ($options as $key => $val) {
            $key = (string) $key;

            if (is_array($val)) {
                $form .= '<optgroup label="'.$key.'">'."\n";

                foreach ($val as $optgroup_key => $optgroup_val) {
                    $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';

                    $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
                }

                $form .= '</optgroup>'."\n";
            } else {
                $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';

                $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
            }
        }

        $form .= '</select>';

        return $form;
    }
791695
public function makeText($config, $population, $custom)
    {
        return '<textarea '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'" placeholder="'.$config['placeholder'].'">'.$population.'</textarea>';
    }
302822
public static function generateSelectOptions( $data, $selected = null, $key1, $key2 ) {

		$options	= "";

		if( isset( $data ) ) {

			if( isset($selected) ) {

				foreach ( $data as $key => $value ) {

					$val	= $value[ $key1 ];
					$option = $value[ $key2 ];

					if( $selected === $val ) {

						$options .= "<option value='$val' selected>$option</option>";
					}
					else {
						$options .= "<option value='$val'>$option</option>";
					}
				}
			}
			else {

				foreach ( $data as $key => $value ) {

					$val	= $value[ $key1 ];
					$option = $value[ $key2 ];

					$options .= "<option value='$val'>$option</option>";
				}
			}
		}

		return $options;
	}