← Back to team overview

anewt-developers team mailing list archive

[Branch ~sander-sinaasappel/anewt/anewt.new.cxs] Rev 1486: [form] Test whether an option is selected on AnewtFormControlChoice

 

------------------------------------------------------------
revno: 1486
committer: Sander van Schouwenburg <sander@xxxxxxxxxxxxx>
branch nick: anewt.new.cxs
timestamp: Mon 2010-01-04 14:01:54 +0100
message:
  [form] Test whether an option is selected on AnewtFormControlChoice
  
  AnewtFormControlChoice::is_selected($value) returns whether option $value is
  selected.
  
  (from anewt.new.svn:95)
modified:
  form/controls/choice.lib.php


--
lp:~sander-sinaasappel/anewt/anewt.new.cxs
https://code.launchpad.net/~sander-sinaasappel/anewt/anewt.new.cxs

Your team Anewt developers is subscribed to branch lp:~sander-sinaasappel/anewt/anewt.new.cxs.
To unsubscribe from this branch go to https://code.launchpad.net/~sander-sinaasappel/anewt/anewt.new.cxs/+edit-subscription.
=== modified file 'form/controls/choice.lib.php'
--- form/controls/choice.lib.php	2009-07-21 08:31:24 +0000
+++ form/controls/choice.lib.php	2010-01-04 13:01:54 +0000
@@ -232,6 +232,24 @@
 	}
 
 	/**
+	 * Returns whether a certain value is selected. Especially useful when
+	 * \c multiple is enabled.
+	 *
+	 * \param $value
+	 *
+	 * \return
+	 *   Whether an option with the value \c value is selected.
+	 */
+	function is_selected($value)
+	{
+		foreach ($this->_options as $option_or_option_group) {
+			if ($option_or_option_group->is_selected($value))
+				return true;
+		}
+		return false;
+	}
+
+	/**
 	 * \private
 	 *
 	 * Setter method to enable the correct options.
@@ -621,6 +639,20 @@
 	}
 
 	/**
+	 * Returns whether a certain value is selected. Especially useful when
+	 * \c multiple is enabled.
+	 *
+	 * \param $value
+	 *
+	 * \return
+	 *   Whether an option with the value \c value is selected.
+	 */
+	function is_selected($value)
+	{
+		return $this->get('value') == $value && $this->_selected;
+	}
+
+	/**
 	 * \private
 	 *
 	 * Set the value for this group.
@@ -907,6 +939,24 @@
 	}
 
 	/**
+	 * Returns whether a certain value is selected. Especially useful when
+	 * \c multiple is enabled.
+	 *
+	 * \param $value
+	 *
+	 * \return
+	 *   Whether an option with the value \c value is selected.
+	 */
+	function is_selected($value)
+	{
+		foreach ($this->_options as $option) {
+			if ($option->is_selected($value))
+				return true;
+		}
+		return false;
+	}
+
+	/**
 	 * \private
 	 *
 	 * Set the value for this group.