From 8ab196ce6c2d5de323bdd8ebcc11a73814c0cdca Mon Sep 17 00:00:00 2001
From: xue <>
Date: Wed, 26 Apr 2006 21:18:01 +0000
Subject: Merge from 3.0 branch till 971.
---
.../Web/UI/WebControls/TDataTypeValidator.php | 13 ++
.../Web/UI/WebControls/TListControlValidator.php | 132 +++++++++++----------
framework/Web/UI/WebControls/TLiteral.php | 7 +-
framework/Web/UI/WebControls/TTable.php | 2 +-
4 files changed, 87 insertions(+), 67 deletions(-)
(limited to 'framework/Web/UI/WebControls')
diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php
index d78be7bf..ebcaace7 100644
--- a/framework/Web/UI/WebControls/TDataTypeValidator.php
+++ b/framework/Web/UI/WebControls/TDataTypeValidator.php
@@ -98,6 +98,19 @@ class TDataTypeValidator extends TBaseValidator
return true;
}
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['DataType']=$this->getDataType();
+ if(($dateFormat=$this->getDateFormat())!=='')
+ $options['DateFormat']=$dateFormat;
+ return $options;
+ }
+
/**
* This method overrides the parent's implementation.
* The validation succeeds if the input data is of valid type.
diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php
index 9264e891..0d0940ab 100644
--- a/framework/Web/UI/WebControls/TListControlValidator.php
+++ b/framework/Web/UI/WebControls/TListControlValidator.php
@@ -1,5 +1,4 @@
TListControl that allows multiple selection.
+ * for a TListControl that allows multiple selection.
*
* You can specify the minimum or maximum (or both) number of selections
* required using the {@link setMinSelection MinSelection} and
@@ -37,9 +36,9 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
*
*
*
- *
*
* - "value1" must be selected and at least 1 other
@@ -47,14 +46,14 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
*
*
*
- *
+ *
*
*
- *
+ * ErrorMessage="Please select 'item1' and at least 1 other" />
*
*
* @author Xiang Wei Zhuo
@@ -63,112 +62,115 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* @since 3.0
*/
class TListControlValidator extends TBaseValidator
-{
+{
/**
- * @return int min number of selections
+ * @return integer min number of selections. Defaults to -1, meaning not set.
*/
- function getMinSelection()
+ public function getMinSelection()
{
- return $this->getViewState('MinSelection','');
+ return $this->getViewState('MinSelection',-1);
}
-
+
/**
- * @param int minimum number of selections.
+ * @param integer minimum number of selections.
*/
- function setMinSelection($value)
+ public function setMinSelection($value)
{
- $this->setViewState('MinSelection',$value,'');
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ $this->setViewState('MinSelection',$value,-1);
}
-
+
/**
- * @return int max number of selections
+ * @return integer max number of selections. Defaults to -1, meaning not set.
*/
- function getMaxSelection()
+ public function getMaxSelection()
{
- return $this->getViewState('MaxSelection','');
+ return $this->getViewState('MaxSelection',-1);
}
-
+
/**
- * @param int max number of selections.
- */
- function setMaxSelection($value)
+ * @param integer max number of selections.
+ */
+ public function setMaxSelection($value)
{
- $this->setViewState('MaxSelection',$value,'');
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ $this->setViewState('MaxSelection',$value,-1);
}
/**
* Get a comma separated list of required selected values.
- * @return string comma separated list of required values.
+ * @return string comma separated list of required values.
*/
- function getRequiredSelections()
+ public function getRequiredSelections()
{
return $this->getViewState('RequiredSelections','');
}
-
+
/**
* Set the list of required values, using aa comma separated list.
- * @param string comma separated list of required values.
+ * @param string comma separated list of required values.
*/
- function setRequiredSelections($value)
+ public function setRequiredSelections($value)
{
$this->setViewState('RequiredSelections',$value,'');
- }
-
+ }
+
/**
* This method overrides the parent's implementation.
* The validation succeeds if the input component changes its data
* from the InitialValue or the input component is not given.
* @return boolean whether the validation succeeds
*/
- public function evaluateIsValid()
- {
+ protected function evaluateIsValid()
+ {
$control=$this->getValidationTarget();
-
+
$exists = true;
- list($count, $values) = $this->getSelection($control);
+ $values = $this->getSelection($control);
+ $count = count($values);
$required = $this->getRequiredValues();
-
+
//if required, check the values
if(!empty($required))
{
- if(count($values) < count($required) )
+ if($count < count($required) )
return false;
foreach($required as $require)
$exists = $exists && in_array($require, $values);
}
-
+
$min = $this->getMinSelection();
$max = $this->getMaxSelection();
-
- if($min !== '' && $max !=- '')
- return $exists && $count >= intval($min) && $count <= intval($max);
- else if($min === '' && $max !== '')
- return $exists && $count <= intval($max);
- else if($min !== '' && $max === '')
- return $exists && $count >= intval($min);
- }
-
+
+ if($min !== -1 && $max !== -1)
+ return $exists && $count >= $min && $count <= $max;
+ else if($min === -1 && $max !== -1)
+ return $exists && $count <= $max;
+ else if($min !== -1 && $max === -1)
+ return $exists && $count >= $min;
+ else
+ return $exists;
+ }
+
/**
* @param TListControl control to validate
* @return array number of selected values and its values.
*/
protected function getSelection($control)
{
- $count = 0;
$values = array();
//get the data
foreach($control->getItems() as $item)
{
- if($item->getSelected())
- {
- $count++;
+ if($item->getSelected())
$values[] = $item->getValue();
- }
}
- return array($count, $values);
+ return $values;
}
-
+
/**
* @return array list of required values.
*/
@@ -180,7 +182,7 @@ class TListControlValidator extends TBaseValidator
$required = preg_split('/,\s*/', $string);
return $required;
}
-
+
/**
* Returns an array of javascript validator options.
* @return array javascript validator options.
@@ -189,26 +191,26 @@ class TListControlValidator extends TBaseValidator
{
$options = parent::getClientScriptOptions();
$control = $this->getValidationTarget();
-
+
if(!$control instanceof TListControl)
{
throw new TConfigurationException(
- 'tlistcontrolvalidator_invalid_control',
+ 'tlistcontrolvalidator_invalid_control',
$this->getID(),$this->getControlToValidate(), get_class($control));
}
-
+
$min = $this->getMinSelection();
$max = $this->getMaxSelection();
- if($min !== '')
- $options['Min']= intval($min);
- if($max !== '')
- $options['Max']= intval($max);
+ if($min !== -1)
+ $options['Min']= $min;
+ if($max !== -1)
+ $options['Max']= $max;
$required = $this->getRequiredSelections();
if(strlen($required) > 0)
$options['Required']= $required;
$options['TotalItems'] = $control->getItemCount();
return $options;
- }
+ }
}
?>
\ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TLiteral.php b/framework/Web/UI/WebControls/TLiteral.php
index 35888676..f335499f 100644
--- a/framework/Web/UI/WebControls/TLiteral.php
+++ b/framework/Web/UI/WebControls/TLiteral.php
@@ -15,11 +15,14 @@
*
* TLiteral displays a static text on the Web page.
* TLiteral is similar to the TLabel control, except that the TLiteral
- * control does not allow child controls and do not have style properties (e.g. BackColor, Font, etc.)
+ * control does not have style properties (e.g. BackColor, Font, etc.)
* You can programmatically control the text displayed in the control by setting
* the {@link setText Text} property. The text displayed may be HTML-encoded
* if the {@link setEncode Encode} property is set true (defaults to false).
*
+ * TLiteral will render the contents enclosed within its component tag
+ * if {@link setText Text} is empty.
+ *
* Note, if {@link setEncode Encode} is false, make sure {@link setText Text}
* does not contain unwanted characters that may bring security vulnerabilities.
*
@@ -76,6 +79,8 @@ class TLiteral extends TControl
else
$writer->write($text);
}
+ else
+ parent::renderContents($writer);
}
}
diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php
index fe01649c..4fcbb6fb 100644
--- a/framework/Web/UI/WebControls/TTable.php
+++ b/framework/Web/UI/WebControls/TTable.php
@@ -45,7 +45,7 @@ Prado::using('System.Web.UI.WebControls.TTableRow');
*
*
*
- *
+ *
*
* The above can also be accomplished in code as follows,
*
--
cgit v1.2.3