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
      • 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
    • 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 (http://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Forms\Controls;
  9: 
 10: use Nette,
 11:     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 bool */
 26:     public $generateId = FALSE;
 27: 
 28:     /** @var Html  separator element template */
 29:     protected $separator;
 30: 
 31:     /** @var Html  container element template */
 32:     protected $container;
 33: 
 34:     /** @var Html  item label template */
 35:     protected $itemLabel;
 36: 
 37: 
 38:     /**
 39:      * @param  string  label
 40:      * @param  array   options from which to choose
 41:      */
 42:     public function __construct($label = NULL, array $items = NULL)
 43:     {
 44:         parent::__construct($label, $items);
 45:         $this->control->type = 'radio';
 46:         $this->container = Html::el();
 47:         $this->separator = Html::el('br');
 48:         $this->itemLabel = Html::el();
 49:     }
 50: 
 51: 
 52:     /**
 53:      * Returns selected radio value.
 54:      * @return mixed
 55:      */
 56:     public function getValue()
 57:     {
 58:         return parent::getValue();
 59:     }
 60: 
 61: 
 62:     /**
 63:      * Returns separator HTML element template.
 64:      * @return Html
 65:      */
 66:     public function getSeparatorPrototype()
 67:     {
 68:         return $this->separator;
 69:     }
 70: 
 71: 
 72:     /**
 73:      * Returns container HTML element template.
 74:      * @return Html
 75:      */
 76:     public function getContainerPrototype()
 77:     {
 78:         return $this->container;
 79:     }
 80: 
 81: 
 82:     /**
 83:      * Returns item label HTML element template.
 84:      * @return Html
 85:      */
 86:     public function getItemLabelPrototype()
 87:     {
 88:         return $this->itemLabel;
 89:     }
 90: 
 91: 
 92:     /**
 93:      * Generates control's HTML element.
 94:      * @return Html
 95:      */
 96:     public function getControl()
 97:     {
 98:         $input = parent::getControl();
 99:         $items = $this->getItems();
100:         $ids = array();
101:         if ($this->generateId) {
102:             foreach ($items as $value => $label) {
103:                 $ids[$value] = $input->id . '-' . $value;
104:             }
105:         }
106: 
107:         return $this->container->setHtml(
108:             Nette\Forms\Helpers::createInputList(
109:                 $this->translate($items),
110:                 array_merge($input->attrs, array(
111:                     'id:' => $ids,
112:                     'checked?' => $this->value,
113:                     'disabled:' => $this->disabled,
114:                     'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']),
115:                 )),
116:                 array('for:' => $ids) + $this->itemLabel->attrs,
117:                 $this->separator
118:             )
119:         );
120:     }
121: 
122: 
123:     /**
124:      * Generates label's HTML element.
125:      * @param  string
126:      * @return Html
127:      */
128:     public function getLabel($caption = NULL)
129:     {
130:         return parent::getLabel($caption)->for(NULL);
131:     }
132: 
133: 
134:     /**
135:      * @return Html
136:      */
137:     public function getControlPart($key)
138:     {
139:         return parent::getControl()->addAttributes(array(
140:             'id' => $this->getHtmlId() . '-' . $key,
141:             'checked' => in_array($key, (array) $this->value, TRUE),
142:             'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled,
143:             'value' => $key,
144:         ));
145:     }
146: 
147: 
148:     /**
149:      * @return Html
150:      */
151:     public function getLabelPart($key)
152:     {
153:         return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
154:     }
155: 
156: }
157: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0