iPhone style checkboxes for Symfony


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class sfWidgetFormInputiPhoneCheckbox extends sfWidgetFormInputCheckbox {
  2.  
  3. public function __construct($options = array(), $attributes = array())
  4. {
  5.  
  6. $this->addOption('checked_label');
  7. $this->addOption('un_checked_label');
  8.  
  9. parent::__construct($options, $attributes);
  10. }
  11.  
  12. public function render($name, $value = null, $attributes = array(), $errors = array())
  13. {
  14. $str = parent::render( $name, $value, $attributes, $errors );
  15.  
  16. $checkedLabel = $this->getOption("checked_label");
  17. $uncheckedLabel = $this->getOption("un_checked_label");
  18. $id = $this->generateId($name);
  19.  
  20. $str .= <<<eof><script type="text/javascript">
  21.  
  22. $(document).ready( function(){
  23.  
  24.   $('#$id').iphoneStyle({
  25.   checkedLabel: '$checkedLabel',
  26.   uncheckedLabel: '$uncheckedLabel'
  27.   });
  28.  
  29. });
  30. </script>
  31. EOF;
  32.  
  33. return $str;
  34. }
  35.  
  36. }
  37.  
  38. $this->setWidgets(array(
  39. 'show-upcoming-events-nav' => new sfWidgetFormInputiPhoneCheckbox( array("checked_label" => "on", "un_checked_label" => "off") ),
  40. ));

URL: http://shout.setfive.com/2010/10/13/iphone-style-checkboxes-for-symfony/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.