From 93977e579cca9a9d0df28099e1fb7596bcc1c825 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 15 Dec 2008 09:22:32 +0000 Subject: Refresh of Forge r168 from vendor/forge/modified --- modules/forge/libraries/Form_Dropdown.php | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 modules/forge/libraries/Form_Dropdown.php (limited to 'modules/forge/libraries/Form_Dropdown.php') diff --git a/modules/forge/libraries/Form_Dropdown.php b/modules/forge/libraries/Form_Dropdown.php new file mode 100644 index 00000000..ac810299 --- /dev/null +++ b/modules/forge/libraries/Form_Dropdown.php @@ -0,0 +1,78 @@ + '', + 'class' => 'dropdown', + ); + + 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 + $base_data = $this->data; + + unset($base_data['label']); + + // Get the options and default selection + $options = arr::remove('options', $base_data); + $selected = arr::remove('selected', $base_data); + + return form::dropdown($base_data, $options, $selected); + } + + protected function load_value() + { + if (is_bool($this->valid)) + return; + + $this->data['selected'] = $this->input_value($this->name); + } + + public function validate() + { + // Validation has already run + if (is_bool($this->is_valid)) + return $this->is_valid; + + if ($this->input_value() == FALSE) + { + // No data to validate + return $this->is_valid = FALSE; + } + + // Load the submitted value + $this->load_value(); + + if ( ! array_key_exists($this->value, $this->data['options'])) + { + // Value does not exist in the options + return $this->is_valid = FALSE; + } + + return parent::validate(); + } + +} // End Form Dropdown \ No newline at end of file -- cgit v1.2.3