Return to Snippet

Revision: 34013
at October 15, 2010 22:32 by metoikos


Initial Code
class sfWidgetFormInputiPhoneCheckbox extends sfWidgetFormInputCheckbox {

	public function __construct($options = array(), $attributes = array())
	{

		$this->addOption('checked_label');
        $this->addOption('un_checked_label');

		parent::__construct($options, $attributes);
	}

	public function render($name, $value = null, $attributes = array(), $errors = array())
	{
		$str = parent::render( $name, $value, $attributes, $errors );

		$checkedLabel = $this->getOption("checked_label");
        $uncheckedLabel = $this->getOption("un_checked_label");
        $id = $this->generateId($name);

		$str .= <<<eof><script type="text/javascript">

		  $(document).ready( function(){

                $('#$id').iphoneStyle({
                    checkedLabel: '$checkedLabel',
                    uncheckedLabel: '$uncheckedLabel'
                });

		  });
		</script>
EOF;

		return $str;
	}

}

$this->setWidgets(array(  
   'show-upcoming-events-nav' => new sfWidgetFormInputiPhoneCheckbox( array("checked_label" => "on", "un_checked_label" => "off") ),  
));

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

Initial Description


Initial Title
iPhone style checkboxes for Symfony

Initial Tags
form, php

Initial Language
PHP