| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_Input_Radio extends HC3_Ui_Abstract_Input |
| 3 |
{ |
| 4 |
protected $el = 'input'; |
| 5 |
protected $uiType = 'input/radio'; |
| 6 |
protected $checked = false; |
| 7 |
protected $asList = false; |
| 8 |
|
| 9 |
public function __construct( $htmlFactory, $name, $label = NULL, $value = NULL, $checked = FALSE ) |
| 10 |
{ |
| 11 |
parent::__construct( $htmlFactory, $name, $label, $value ); |
| 12 |
$this->checked = $checked; |
| 13 |
} |
| 14 |
|
| 15 |
public function asList( $set = TRUE ) |
| 16 |
{ |
| 17 |
$this->asList = $set; |
| 18 |
return $this; |
| 19 |
} |
| 20 |
|
| 21 |
public function render() |
| 22 |
{ |
| 23 |
$out = $this->htmlFactory->makeElement('input') |
| 24 |
->addAttr('type', 'radio' ) |
| 25 |
->addAttr('name', $this->htmlName() ) |
| 26 |
// ->addAttr('class', 'hc-field') |
| 27 |
; |
| 28 |
|
| 29 |
if( strlen($this->value) ){ |
| 30 |
$out->addAttr('value', $this->value); |
| 31 |
} |
| 32 |
|
| 33 |
if( $this->checked ){ |
| 34 |
$out->addAttr('checked', 'checked'); |
| 35 |
} |
| 36 |
|
| 37 |
$out->addAttr('id', $this->htmlId()); |
| 38 |
|
| 39 |
$attr = $this->getAttr(); |
| 40 |
foreach( $attr as $k => $v ){ |
| 41 |
$out->addAttr($k, $v); |
| 42 |
} |
| 43 |
|
| 44 |
if( strlen($this->label) ){ |
| 45 |
$label = $this->htmlFactory->makeElement('label', $this->label) |
| 46 |
->addAttr('for', $this->htmlId()) |
| 47 |
// ->addAttr('class', 'hc-fs2') |
| 48 |
; |
| 49 |
|
| 50 |
if( $this->asList ){ |
| 51 |
$out = $this->htmlFactory->makeList( array($out, $label) )->gutter(0); |
| 52 |
$out = $this->htmlFactory->makeBlock( $out ) |
| 53 |
->addAttr('class', 'hc-align-center') |
| 54 |
; |
| 55 |
} |
| 56 |
else { |
| 57 |
$out = $this->htmlFactory->makeListInline( array($out, $label) )->gutter(1); |
| 58 |
$out = $this->htmlFactory->makeBlock( $out ) |
| 59 |
->addAttr('class', 'hc-nowrap') |
| 60 |
; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return $out; |
| 65 |
} |
| 66 |
} |