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