1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
<?php
namespace MvcCore\Ext\Form;
require_once('Core/Field.php');
class Checkbox extends Core\Field
{
public $Type = 'checkbox';
public $LabelSide = 'right';
public $Validators = array('SafeString');
public static $Templates = array(
'control' => '<input id="{id}" name="{name}" type="checkbox" value="true"{value}{attrs} />',
'togetherLabelLeft' => '<label for="{id}"{attrs}><span>{label}</span>{control}</label>',
'togetherLabelRight'=> '<label for="{id}"{attrs}>{control}<span>{label}</span></label>',
);
public function __construct(array $cfg = array()) {
parent::__construct($cfg);
static::$Templates = (object) array_merge((array)parent::$Templates, (array)self::$Templates);
}
public function RenderControl () {
$attrsStr = $this->renderControlAttrsWithFieldVars();
include_once('Core/View.php');
return Core\View::Format(static::$Templates->control, array(
'id' => $this->Id,
'name' => $this->Name,
'value' => $this->Value ? ' checked="checked"' : '',
'attrs' => $attrsStr ? " $attrsStr" : '',
));
}
}