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