Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • BaseControl
  • Button
  • Checkbox
  • CheckboxList
  • ChoiceControl
  • CsrfProtection
  • HiddenField
  • ImageButton
  • MultiChoiceControl
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Forms\Controls;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Select box control that allows multiple items selection.
15:  */
16: class MultiSelectBox extends MultiChoiceControl
17: {
18:     /** @var array of option / optgroup */
19:     private $options = array();
20: 
21: 
22:     /**
23:      * Sets options and option groups from which to choose.
24:      * @return static
25:      */
26:     public function setItems(array $items, $useKeys = TRUE)
27:     {
28:         if (!$useKeys) {
29:             $res = array();
30:             foreach ($items as $key => $value) {
31:                 unset($items[$key]);
32:                 if (is_array($value)) {
33:                     foreach ($value as $val) {
34:                         $res[$key][(string) $val] = $val;
35:                     }
36:                 } else {
37:                     $res[(string) $value] = $value;
38:                 }
39:             }
40:             $items = $res;
41:         }
42:         $this->options = $items;
43:         return parent::setItems(Nette\Utils\Arrays::flatten($items, TRUE));
44:     }
45: 
46: 
47:     /**
48:      * Generates control's HTML element.
49:      * @return Nette\Utils\Html
50:      */
51:     public function getControl()
52:     {
53:         $items = array();
54:         foreach ($this->options as $key => $value) {
55:             $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
56:         }
57: 
58:         return Nette\Forms\Helpers::createSelectBox(
59:             $items,
60:             array(
61:                 'selected?' => $this->value,
62:                 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL,
63:             )
64:         )->addAttributes(parent::getControl()->attrs)->multiple(TRUE);
65:     }
66: 
67: }
68: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0