Source for file Checkbox.php

Documentation is available at Checkbox.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette\Forms
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * Check box control. Allows the user to select a true or false condition.
  17. 17:  *
  18. 18:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  19. 19:  * @package    Nette\Forms
  20. 20:  */
  21. 21: class Checkbox extends FormControl
  22. 22: {
  23. 23:  
  24. 24:     /**
  25. 25:      * @param  string  label
  26. 26:      */
  27. 27:     public function __construct($label NULL)
  28. 28:     {
  29. 29:         parent::__construct($label);
  30. 30:         $this->control->type 'checkbox';
  31. 31:         $this->value = FALSE;
  32. 32:     }
  33. 33:  
  34. 34:  
  35. 35:  
  36. 36:     /**
  37. 37:      * Sets control's value.
  38. 38:      * @param  bool 
  39. 39:      * @return Checkbox  provides a fluent interface
  40. 40:      */
  41. 41:     public function setValue($value)
  42. 42:     {
  43. 43:         $this->value = is_scalar($value? (bool) $value FALSE;
  44. 44:         return $this;
  45. 45:     }
  46. 46:  
  47. 47:  
  48. 48:  
  49. 49:     /**
  50. 50:      * Generates control's HTML element.
  51. 51:      * @return Html 
  52. 52:      */
  53. 53:     public function getControl()
  54. 54:     {
  55. 55:         return parent::getControl()->checked($this->value);
  56. 56:     }
  57. 57:  
  58. 58: }