Namespaces

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

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