* @version $Revision: $ $Date: $
@@ -29,14 +29,24 @@ Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
*/
class TEmailAddressValidator extends TRegularExpressionValidator
{
+ /**
+ * Regular expression used to validate the email address
+ */
const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
+ /**
+ * @return string the regular expression that determines the pattern used to validate a field.
+ */
public function getRegularExpression()
{
$regex=parent::getRegularExpression();
return $regex===''?self::EMAIL_REGEXP:$regex;
}
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
public function evaluateIsValid()
{
$valid=parent::evaluateIsValid();
diff --git a/framework/Web/UI/WebControls/TRegularExpressionValidator.php b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
index 9fe0f778..f20c2d16 100644
--- a/framework/Web/UI/WebControls/TRegularExpressionValidator.php
+++ b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
@@ -21,7 +21,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* TRegularExpressionValidator validates whether the value of an associated
* input component matches the pattern specified by a regular expression.
*
- * You can specify the regular expression by setting the RegularExpression
+ * You can specify the regular expression by setting the {@link setRegularExpression RegularExpression}
* property. Some commonly used regular expressions include:
*
* French Phone Number: (0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d
@@ -40,6 +40,9 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* U.S. Social Security Number: \d{3}-\d{2}-\d{4}
*
*
+ * Note, the validation succeeds if the associated input control contains empty input.
+ * Use a {@link TRequiredFieldValidator} to ensure the input is not empty.
+ *
* @author Qiang Xue
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
@@ -56,8 +59,7 @@ class TRegularExpressionValidator extends TBaseValidator
}
/**
- * Sets the regular expression that determines the pattern used to validate a field.
- * @param string the regular expression
+ * @param string the regular expression that determines the pattern used to validate a field.
*/
public function setRegularExpression($value)
{
@@ -73,19 +75,18 @@ class TRegularExpressionValidator extends TBaseValidator
*/
public function evaluateIsValid()
{
- if(($control=$this->getValidationTarget())!==null)
- {
- if(($value=$this->getValidationValue($control))==='')
- return true;
- if(($expression=$this->getRegularExpression())!=='')
- return preg_match("/^$expression\$/",$value);
- else
- return true;
- }
+ if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
+ return true;
+ if(($expression=$this->getRegularExpression())!=='')
+ return preg_match("/^$expression\$/",$value);
else
- throw new TInvalidDataValueException('regularexpressionvalidator_controltovalidate_invalid');
+ return true;
}
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
protected function getClientScriptOptions()
{
$options = parent::getClientScriptOptions();
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
index c937abf8..2d1dd612 100644
--- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php
+++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
@@ -18,6 +18,9 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
/**
* TRequiredFieldValidator class
*
+ * TRequiredFieldValidator makes the associated input control a required field.
+ * The input control fails validation if its value does not change from
+ * the {@link setInitialValue InitialValue} property upon losing focus.
*
* @author Qiang Xue
* @version $Revision: $ $Date: $
@@ -26,27 +29,42 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
*/
class TRequiredFieldValidator extends TBaseValidator
{
+ /**
+ * @return string the initial value of the associated input control. Defaults to empty string.
+ * If the associated input control does not change from this initial value
+ * upon postback, the validation fails.
+ */
public function getInitialValue()
{
$this->getViewState('InitialValue','');
}
+ /**
+ * @param string the initial value of the associated input control.
+ * If the associated input control does not change from this initial value
+ * upon postback, the validation fails.
+ */
public function setInitialValue($value)
{
$this->setViewState('InitialValue',TPropertyValue::ensureString($value),'');
}
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input component changes its data
+ * from the {@link getInitialValue InitialValue} or the input control is not given.
+ * @return boolean whether the validation succeeds
+ */
protected function evaluateIsValid()
{
- if(($control=$this->getValidationTarget())!==null)
- {
- $value=$this->getValidationValue($control);
- return trim($value)!==trim($this->getInitialValue());
- }
- else
- throw new TInvalidDataValueException('requiredfieldvalidator_controltovalidate_invalid');
+ $value=$this->getValidationValue($this->getValidationTarget());
+ return trim($value)!==trim($this->getInitialValue());
}
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
protected function getClientScriptOptions()
{
$options = parent::getClientScriptOptions();
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 0ac7584a..056c8f3e 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -13,29 +13,21 @@
/**
* TValidationSummary class
*
- * TValidationSummary displays a summary of all validation errors inline on a Web page,
- * in a message box, or both. The summary can be displayed as a list, as a bulleted list,
- * or as a single paragraph based on the DisplayMode property.
- * The summary can be displayed on the Web page and in a message box by setting
- * the ShowSummary and ShowMessageBox properties, respectively.
+ * TValidationSummary displays a summary of validation errors inline on a Web page,
+ * in a message box, or both. By default, a validation summary will collect
+ * {@link TBaseValidator::getErrorMessage ErrorMessage} of all failed validators
+ * on the page. If {@link getValidationGroup ValidationGroup} is not
+ * empty, only those validators who belong to the group will show their error messages
+ * in the summary.
*
- * Namespace: System.Web.UI.WebControls
+ * The summary can be displayed as a list, as a bulleted list, or as a single
+ * paragraph based on the {@link setDisplayMode DisplayMode} property.
+ * The messages shown can be prefixed with {@link setHeaderText HeaderText}.
*
- * Properties
- * - DisplayMode, string, default=BulletList, kept in viewstate
- *
Gets or sets the display mode (BulletList, List, SingleParagraph) of the validation summary.
- * - HeaderText, string, kept in viewstate
- *
Gets or sets the header text displayed at the top of the summary.
- * - EnableClientScript, boolean, default=true, kept in viewstate
- *
Gets or sets a value indicating whether the TValidationSummary component
- * updates itself using client-side script.
- * - ShowMessageBox, boolean, default=false, kept in viewstate
- *
Gets or sets a value indicating whether the validation summary is displayed in a message box.
- * If EnableClientScript is false, this property has no effect.
- * - ShowSummary, boolean, default=true, kept in viewstate
- *
Gets or sets a value indicating whether the validation summary is displayed inline.
- * - Group, string, kept in viewstate
- *
Gets or sets the validation group ID.
+ * The summary can be displayed on the Web page and in a message box by setting
+ * the {@link setShowSummary ShowSummary} and {@link setShowMessageBox ShowMessageBox}
+ * properties, respectively. Note, the latter is only effective when
+ * {@link setEnableClientScript EnableClientScript} is true.
*
* @author Qiang Xue
* @version $Revision: $ $Date: $
@@ -44,20 +36,6 @@
*/
class TValidationSummary extends TWebControl
{
-
- protected static $currentGroup;
-
- public static function setCurrentGroup($group)
- {
- self::$currentGroup = $group;
- }
-
- public static function getCurrentGroup()
- {
- return self::$currentGroup;
- }
-
-
/**
* @return string the header text displayed at the top of the summary
*/
@@ -190,29 +168,6 @@ class TValidationSummary extends TWebControl
$this->setViewState('ValidationGroup',$value,'');
}
- /**
- * Get a list of validators considering the validation groups.
- * @return array list of validators.
- */
- protected function getValidators()
- {
- $groupID = $this->getGroup();
- if(empty($groupID)) return $this->getPage()->getValidators();
-
- $parent = $this->getParent();
- $group = $parent->findObject($groupID);
-
- $validators = array();
-
- foreach($group->getMembers() as $member)
- {
- $control = $parent->findObject($member);
- if(!is_null($control))
- $validators[] = $control;
- }
- return $validators;
- }
-
protected function addAttributesToRender($writer)
{
$writer->addAttribute('id',$this->getClientID());
@@ -341,11 +296,13 @@ class TValidationSummary extends TWebControl
$header=$this->getHeaderText();
$messages=$this->getErrorMessages();
$content = $header;
- $show = count($messages) > 0;
- if($show) $content .= "\n";
- foreach($messages as $message)
- $content.= '- '.$message."
\n";
- if($show) $content .= "
\n";
+ if(count($messages)>0)
+ {
+ $content .= "\n";
+ foreach($messages as $message)
+ $content.= '- '.$message."
\n";
+ $content .= "
\n";
+ }
$writer->write($content);
}
}
--
cgit v1.2.3