Author: david
Date: Tue Nov 24 16:47:33 2009
New Revision: 3958

Log:
Add multiple input form widget.

Added:
   trunk/lib/QubitWidgetFormInputMany.php   (contents, props changed)

Added: trunk/lib/QubitWidgetFormInputMany.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/QubitWidgetFormInputMany.php      Tue Nov 24 16:47:33 2009        
(r3958)
@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * sfWidgetFormSelectMany represents an HTML input tag with multiple values.
+ * Because HTML doesn't support multi-value inputs natively, we are faking it
+ * with a list of related inputs.
+ *
+ * @package    Qubit
+ * @subpackage widget
+ * @author     David Juhasz <[email protected]>
+ * @version    SVN: $Id$
+ */
+class QubitWidgetFormInputMany extends sfWidgetFormInput
+{
+  /**
+   * @param array $options     An array of options
+   * @param array $attributes  An array of default HTML attributes
+   *
+   * @see sfWidgetFormSelect
+   */
+  protected function configure($options = array(), $attributes = array())
+  {
+    parent::configure($options, $attributes);
+    $this->addRequiredOption('defaultNames');
+  }
+
+  /**
+   * @param  string $name        The element name
+   * @param  string $value       The value displayed in this widget
+   * @param  array  $attributes  An array of HTML attributes to be merged with 
the default HTML attributes
+   * @param  array  $errors      An array of errors for the field
+   *
+   * @return string An HTML tag string
+   *
+   * @see sfWidgetForm
+   */
+  public function render($name, $value = null, $attributes = array(), $errors 
= array())
+  {
+    $inputStr = '';
+
+    $defaultNames = $this->getOption('defaultNames');
+    if ($defaultNames instanceof sfCallable)
+    {
+      $defaultNames = $defaultNames->call();
+    }
+
+    if (is_array($defaultNames) && 0 < count($defaultNames))
+    {
+      $inputStr .= "<ul>\n";
+      foreach ($defaultNames as $key => $choice)
+      {
+        $inputStr .= "\t<li>".$this->renderTag('input', 
array_merge(array('type' => $this->getOption('type'), 'name' => 
$name.'['.$key.']', 'value' => $choice), $attributes))."</li>\n";
+      }
+      $inputStr .= "</ul>\n";
+    }
+
+    $inputStr .= $this->renderTag('input', array('name' => $name.'[]', 'type' 
=> $this->getOption('type')));
+
+    return $inputStr;
+  }
+}
\ No newline at end of file

--

You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.


Reply via email to