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