← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1814: [form] Minor logic cleanup in choice control

 

------------------------------------------------------------
revno: 1814
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt
timestamp: Thu 2011-03-17 14:25:41 +0100
message:
  [form] Minor logic cleanup in choice control
modified:
  form/controls/choice.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription
=== modified file 'form/controls/choice.lib.php'
--- form/controls/choice.lib.php	2009-08-02 20:04:03 +0000
+++ form/controls/choice.lib.php	2011-03-17 13:25:41 +0000
@@ -206,8 +206,9 @@
 	 * External callers should use <code>get('value')</code> instead.
 	 *
 	 * \return
-	 *   An array values when \c multiple is enabled, a single value if this is
-	 *   a single select control.
+	 *   An array of values (may be zero length) for multiple-select controls
+	 *   (when \c multiple is enabled), or a single value (may be
+	 *   <code>null</code>) for single select controls.
 	 */
 	function get_value()
 	{
@@ -221,15 +222,20 @@
 
 			/* Break early if only one value is needed */
 			if (!$multiple && $values)
-				return $values[0];
+				break;
 		}
 
-		/* If this is a single select control, but no value was set, null is
-		 * returned. */
-		if (!$multiple)
-			return null;
-
-		return $values;
+		/* Return all values for multiple-select controls. This may be an empty
+		 * list. */
+		if ($multiple)
+			return $values;
+
+		/* Return the first value (if any) for single-select controls */
+		if ($values)
+			return $values[0];
+
+		/* No value set; return null */
+		return null;
 	}
 
 	/**