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