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
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

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