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
      • 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
  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: use Nette\Utils\Html;
 12: 
 13: 
 14: /**
 15:  * Set of checkboxes.
 16:  *
 17:  * @property-read Html $separatorPrototype
 18:  * @property-read Html $containerPrototype
 19:  */
 20: class CheckboxList extends MultiChoiceControl
 21: {
 22:     /** @var Html  separator element template */
 23:     protected $separator;
 24: 
 25:     /** @var Html  container element template */
 26:     protected $container;
 27: 
 28: 
 29:     /**
 30:      * @param  string  label
 31:      * @param  array   options from which to choose
 32:      */
 33:     public function __construct($label = NULL, array $items = NULL)
 34:     {
 35:         parent::__construct($label, $items);
 36:         $this->control->type = 'checkbox';
 37:         $this->container = Html::el();
 38:         $this->separator = Html::el('br');
 39:         $this->setOption('type', 'checkbox');
 40:     }
 41: 
 42: 
 43:     /**
 44:      * Generates control's HTML element.
 45:      * @return Html
 46:      */
 47:     public function getControl()
 48:     {
 49:         $input = parent::getControl();
 50:         $items = $this->getItems();
 51:         reset($items);
 52: 
 53:         return $this->container->setHtml(
 54:             Nette\Forms\Helpers::createInputList(
 55:                 $this->translate($items),
 56:                 array_merge($input->attrs, [
 57:                     'id' => NULL,
 58:                     'checked?' => $this->value,
 59:                     'disabled:' => $this->disabled,
 60:                     'required' => NULL,
 61:                     'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']],
 62:                 ]),
 63:                 $this->label->attrs,
 64:                 $this->separator
 65:             )
 66:         );
 67:     }
 68: 
 69: 
 70:     /**
 71:      * Generates label's HTML element.
 72:      * @param  string
 73:      * @return Html
 74:      */
 75:     public function getLabel($caption = NULL)
 76:     {
 77:         return parent::getLabel($caption)->for(NULL);
 78:     }
 79: 
 80: 
 81:     /**
 82:      * @return Html
 83:      */
 84:     public function getControlPart($key = NULL)
 85:     {
 86:         $key = key([(string) $key => NULL]);
 87:         return parent::getControl()->addAttributes([
 88:             'id' => $this->getHtmlId() . '-' . $key,
 89:             'checked' => in_array($key, (array) $this->value, TRUE),
 90:             'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled,
 91:             'required' => NULL,
 92:             'value' => $key,
 93:         ]);
 94:     }
 95: 
 96: 
 97:     /**
 98:      * @return Html
 99:      */
100:     public function getLabelPart($key = NULL)
101:     {
102:         return func_num_args()
103:             ? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key)
104:             : $this->getLabel();
105:     }
106: 
107: 
108:     /**
109:      * Returns separator HTML element template.
110:      * @return Html
111:      */
112:     public function getSeparatorPrototype()
113:     {
114:         return $this->separator;
115:     }
116: 
117: 
118:     /**
119:      * Returns container HTML element template.
120:      * @return Html
121:      */
122:     public function getContainerPrototype()
123:     {
124:         return $this->container;
125:     }
126: 
127: }
128: 
Nette 2.4-20161109 API API documentation generated by ApiGen 2.8.0