summaryrefslogtreecommitdiff
path: root/modules/forge/libraries/Form_Dropdown.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
committerBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
commiteba717f95f586d2538007bd18da6e9b32b076c30 (patch)
tree15fc596a270f9de0d163c66c96e3c65fca5ee100 /modules/forge/libraries/Form_Dropdown.php
parentfff10f8b70376ef25722bd867df26bc5aefced43 (diff)
Merge over vendor code.
git-svn-id: http://gallery.svn.sourceforge.net/svnroot/gallery/trunk/eval/gx/gallery3/trunk@18408 57fcd75e-5312-0410-8df3-f5eb6fbb1595
Diffstat (limited to 'modules/forge/libraries/Form_Dropdown.php')
-rw-r--r--modules/forge/libraries/Form_Dropdown.php78
1 files changed, 78 insertions, 0 deletions
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 @@
+<?php
+/**
+ * FORGE dropdown input library.
+ *
+ * $Id$
+ *
+ * @package Forge
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Form_Dropdown_Core extends Form_Input {
+
+ protected $data = array
+ (
+ 'name' => '',
+ '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