PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Nette/Forms/Controls/Checkbox.php

https://github.com/DocX/nette
PHP | 72 lines | 20 code | 16 blank | 36 comment | 0 complexity | 6c7b7efd629dbd9c45ace0227ebfbc44 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette\Forms
  17. */
  18. /*namespace Nette\Forms;*/
  19. require_once dirname(__FILE__) . '/../../Forms/Controls/FormControl.php';
  20. /**
  21. * Check box control. Allows the user to select a true or false condition.
  22. *
  23. * @author David Grudl
  24. * @copyright Copyright (c) 2004, 2009 David Grudl
  25. * @package Nette\Forms
  26. */
  27. class Checkbox extends FormControl
  28. {
  29. /**
  30. * @param string label
  31. */
  32. public function __construct($label = NULL)
  33. {
  34. parent::__construct($label);
  35. $this->control->type = 'checkbox';
  36. $this->value = FALSE;
  37. }
  38. /**
  39. * Sets control's value.
  40. * @param bool
  41. * @return Checkbox provides a fluent interface
  42. */
  43. public function setValue($value)
  44. {
  45. $this->value = is_scalar($value) ? (bool) $value : FALSE;
  46. return $this;
  47. }
  48. /**
  49. * Generates control's HTML element.
  50. * @return Nette\Web\Html
  51. */
  52. public function getControl()
  53. {
  54. return parent::getControl()->checked($this->value);
  55. }
  56. }