Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • none

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