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: 
 12: 
 13: /**
 14:  * Check box control. Allows the user to select a true or false condition.
 15:  */
 16: class Checkbox extends BaseControl
 17: {
 18:     /** @var Nette\Utils\Html  wrapper element template */
 19:     private $wrapper;
 20: 
 21: 
 22:     /**
 23:      * @param  string  label
 24:      */
 25:     public function __construct($label = NULL)
 26:     {
 27:         parent::__construct($label);
 28:         $this->control->type = 'checkbox';
 29:         $this->wrapper = Nette\Utils\Html::el();
 30:     }
 31: 
 32: 
 33:     /**
 34:      * Sets control's value.
 35:      * @param  bool
 36:      * @return self
 37:      */
 38:     public function setValue($value)
 39:     {
 40:         if (!is_scalar($value) && $value !== NULL) {
 41:             throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));
 42:         }
 43:         $this->value = (bool) $value;
 44:         return $this;
 45:     }
 46: 
 47: 
 48:     /**
 49:      * Is control filled?
 50:      * @return bool
 51:      */
 52:     public function isFilled()
 53:     {
 54:         return $this->getValue() !== FALSE; // back compatibility
 55:     }
 56: 
 57: 
 58:     /**
 59:      * Generates control's HTML element.
 60:      * @return Nette\Utils\Html
 61:      */
 62:     public function getControl()
 63:     {
 64:         return $this->wrapper->setHtml($this->getLabelPart()->insert(0, $this->getControlPart()));
 65:     }
 66: 
 67: 
 68:     /**
 69:      * Bypasses label generation.
 70:      * @return void
 71:      */
 72:     public function getLabel($caption = NULL)
 73:     {
 74:         return NULL;
 75:     }
 76: 
 77: 
 78:     /**
 79:      * @return Nette\Utils\Html
 80:      */
 81:     public function getControlPart()
 82:     {
 83:         return parent::getControl()->checked($this->value);
 84:     }
 85: 
 86: 
 87:     /**
 88:      * @return Nette\Utils\Html
 89:      */
 90:     public function getLabelPart()
 91:     {
 92:         return parent::getLabel();
 93:     }
 94: 
 95: 
 96:     /**
 97:      * Returns wrapper HTML element template.
 98:      * @return Nette\Utils\Html
 99:      */
100:     public function getSeparatorPrototype()
101:     {
102:         return $this->wrapper;
103:     }
104: 
105: }
106: 
Nette 2.3.4 API API documentation generated by ApiGen 2.8.0