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