From 64d6f9aea6916ecb7c25f0fec1cb9cf582cbba55 Mon Sep 17 00:00:00 2001 From: Felix Rabinovich Date: Thu, 1 Jan 2009 22:57:17 +0000 Subject: Standard Forge Library doesn't support radio buttons. Added support from http://forum.kohanaphp.com/comments.php?DiscussionID=164 --- core/libraries/MY_Form_Radio.php | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 core/libraries/MY_Form_Radio.php (limited to 'core') diff --git a/core/libraries/MY_Form_Radio.php b/core/libraries/MY_Form_Radio.php new file mode 100644 index 00000000..27283f1f --- /dev/null +++ b/core/libraries/MY_Form_Radio.php @@ -0,0 +1,61 @@ + '', + 'class' => 'radio', + 'type'=>'radio', + 'options'=>array() + ); + protected $protect = array('type'); + + public function __get($key) { + if ($key == 'value') { + return $this->selected; + } + return parent::__get($key); + } + + public function html_element() { + // Import base data + $data = $this->data; + // Get the options and default selection + $options = arr::remove('options', $data); + $selected = arr::remove('selected', $data); + // martin hack + unset($data['label']); + $html =''; + foreach($options as $option=>$labelText){ + $html .= form::radio(array ('name' => $data['name'], 'id' => $data['name'] . "_" . $option ), + $option, $this->value? $this->value==$option: $data['default']==$option). + form::label($data['name']."_".$option , $labelText)." "; + } + return $html; + } + + protected function load_value() { + if (is_bool($this->valid)) + return; + $this->data['selected'] = $this->input_value($this->name); + } +} // End Form radio -- cgit v1.2.3