summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2006-07-22 01:58:33 +0000
committerwei <>2006-07-22 01:58:33 +0000
commit846f6328a4b9b777da44b1b077a244a5a8d527ce (patch)
treec025546b3b46779995378689164f0d7782043932
parent9ce14c25940da9162a19ccfd85fb4ba7cce1ef6a (diff)
add StringLength, multi-byte, check in TRangeValidator
-rw-r--r--.gitattributes1
-rw-r--r--HISTORY2
-rw-r--r--framework/Web/Javascripts/js/validator.js6
-rw-r--r--framework/Web/Javascripts/prado/validation3.js19
-rw-r--r--framework/Web/UI/WebControls/TRangeValidator.php59
-rw-r--r--tests/FunctionalTests/validators/protected/pages/StringRangeValidator.page12
6 files changed, 90 insertions, 9 deletions
diff --git a/.gitattributes b/.gitattributes
index b64fa5e1..f25805a8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1679,6 +1679,7 @@ tests/FunctionalTests/validators/protected/pages/RangeValidatorString.page -text
tests/FunctionalTests/validators/protected/pages/RegularExpressionValidator.page -text
tests/FunctionalTests/validators/protected/pages/RequiredFieldValidator.page -text
tests/FunctionalTests/validators/protected/pages/RequiredListValidator.page -text
+tests/FunctionalTests/validators/protected/pages/StringRangeValidator.page -text
tests/FunctionalTests/validators/protected/pages/ValidationSummary.page -text
tests/FunctionalTests/validators/protected/pages/config.xml -text
tests/FunctionalTests/validators/tests/ButtonTestCase.php -text
diff --git a/HISTORY b/HISTORY
index a6bae2bb..9fc9ff9a 100644
--- a/HISTORY
+++ b/HISTORY
@@ -8,6 +8,7 @@ CHG: Ticket#206 - TBaseValidator.OnValidate is raised only when the validator is
ENH: Ticket#220 - TClientScripts method to import custom javascript files (Wei)
ENH: Ticket#225 - TRadioButton::getRadioButtonsInGroup() added (Wei)
ENH: Ticket#223 - Use TRequiredFieldValidator for TRadioButtons with GroupName property (Wei)
+ENH: StringLength, multi-byte, check in TRangeValidator (Wei)
ENH: Ticket#263 - TListBox and TDropDownList support optgroup now (Qiang)
ENH: Ticket#277 - Added TControl.CustomData property (Qiang)
ENH: Ticket#287 - TControl::broadcastEvent() may raise events now (Qiang)
@@ -15,6 +16,7 @@ ENH: Ticket#292 - Added THttpRequest::parseUrl() so that it is easier to be exte
ENH: Better URL 'Path' format (Qiang)
NEW: Added TStyleSheet (Wei)
+
Version 3.0.2 July 2, 2006
==========================
BUG: Ticket#182 - List and validator controls cause problem in child classes (Qiang)
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index 959dd193..1480368f 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -174,7 +174,11 @@ return true;switch(this.options.Operator)
return true;}});Prado.WebUI.TRangeValidator=Class.extend(Prado.WebUI.TBaseValidator,{evaluateIsValid:function()
{var value=this.getValidationValue();if(value.length<=0)
return true;if(typeof(this.options.DataType)=="undefined")
-this.options.DataType="String";var min=this.convert(this.options.DataType,this.options.MinValue||null);var max=this.convert(this.options.DataType,this.options.MaxValue||null);value=this.convert(this.options.DataType,value);if(value==null)
+this.options.DataType="String";if(this.options.DataType!="StringLength")
+{var min=this.convert(this.options.DataType,this.options.MinValue||null);var max=this.convert(this.options.DataType,this.options.MaxValue||null);value=this.convert(this.options.DataType,value);}
+else
+{var min=this.options.MinValue||0;var max=this.options.MaxValue||Number.POSITIVE_INFINITY;value=value.length;}
+if(value==null)
return false;var valid=true;if(min!=null)
valid=valid&&value>=min;if(max!=null)
valid=valid&&value<=max;return valid;}});Prado.WebUI.TRegularExpressionValidator=Class.extend(Prado.WebUI.TBaseValidator,{evaluateIsValid:function()
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index 9ee7ed2f..0e765c48 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -1104,11 +1104,20 @@ Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
return true;
if(typeof(this.options.DataType) == "undefined")
this.options.DataType = "String";
-
- var min = this.convert(this.options.DataType, this.options.MinValue || null);
- var max = this.convert(this.options.DataType, this.options.MaxValue || null);
- value = this.convert(this.options.DataType, value);
-
+
+ if(this.options.DataType != "StringLength")
+ {
+ var min = this.convert(this.options.DataType, this.options.MinValue || null);
+ var max = this.convert(this.options.DataType, this.options.MaxValue || null);
+ value = this.convert(this.options.DataType, value);
+ }
+ else
+ {
+ var min = this.options.MinValue || 0;
+ var max = this.options.MaxValue || Number.POSITIVE_INFINITY;
+ value = value.length;
+ }
+
if(value == null)
return false;
diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php
index 9d23eb5e..b54a1684 100644
--- a/framework/Web/UI/WebControls/TRangeValidator.php
+++ b/framework/Web/UI/WebControls/TRangeValidator.php
@@ -34,6 +34,13 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* by {@link TSimpleDateFormatter}. If the property is not set,
* the GNU date syntax is assumed.
* - <b>String</b> A string data type.
+ * - <b>StringLength</b> check for string length.
+ *
+ * The TRangeValidator allows a special DataType "StringLength" that
+ * can be used to verify minimum and maximum string length. The
+ * {@link setCharset Charset} property can be used to force a particular
+ * charset for comparison. Otherwise, the application charset is used and is
+ * defaulted as UTF-8.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -96,13 +103,14 @@ class TRangeValidator extends TBaseValidator
}
/**
- * Sets the data type (Integer, Float, Date, String) that the values being
- * compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Date, String, StringLength) that the
+ * values being compared are converted to before the comparison is made.
* @param string the data type
*/
public function setDataType($value)
{
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum(
+ $value,'Integer','Float','Date','String', 'StringLength'),'String');
}
/**
@@ -123,6 +131,22 @@ class TRangeValidator extends TBaseValidator
}
/**
+ * @param string charset for string length comparison.
+ */
+ public function setCharset($value)
+ {
+ $this->setViewState('Charset', $value, '');
+ }
+
+ /**
+ * @return string charset for string length comparison.
+ */
+ public function getCharset()
+ {
+ return $this->getViewState('Charset', '');
+ }
+
+ /**
* This method overrides the parent's implementation.
* The validation succeeds if the input data is within the range.
* The validation always succeeds if the input data is empty.
@@ -142,6 +166,8 @@ class TRangeValidator extends TBaseValidator
return $this->isValidFloat($value);
case 'Date':
return $this->isValidDate($value);
+ case 'StringLength':
+ return $this->isValidStringLength($value);
default:
return $this->isValidString($value);
}
@@ -238,6 +264,33 @@ class TRangeValidator extends TBaseValidator
$valid=$valid && (strcmp($value,$maxValue)<=0);
return $valid;
}
+
+ /**
+ * @param string string for comparision
+ * @return boolean true if min and max string length are satisfied.
+ */
+ protected function isValidStringLength($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+ $charset = $this->getCharset();
+ if($charset==='')
+ {
+ $app= $this->getApplication()->getGlobalization();
+ $charset = $app ? $app->getCharset() : null;
+ if(!$charset)
+ $charset = 'UTF-8';
+ }
+
+ $length = iconv_strlen($value, $charset);
+ if($minValue!=='')
+ $valid = $valid && $length >= intval($minValue);
+ if($maxValue!=='')
+ $valid = $valid && $length <= intval($maxValue);
+ return $valid;
+ }
/**
* Returns an array of javascript validator options.
diff --git a/tests/FunctionalTests/validators/protected/pages/StringRangeValidator.page b/tests/FunctionalTests/validators/protected/pages/StringRangeValidator.page
new file mode 100644
index 00000000..14f63801
--- /dev/null
+++ b/tests/FunctionalTests/validators/protected/pages/StringRangeValidator.page
@@ -0,0 +1,12 @@
+<com:TContent ID="Content">
+
+ <com:TTextBox ID="text1" />
+ <com:TRangeValidator
+ ControlToValidate="text1"
+ MinValue="5"
+ MaxValue="7"
+ DataType="StringLength"
+ ErrorMessage="String length must be between 5 and 7" />
+ <com:TButton Text="Submit!" />
+
+</com:TContent> \ No newline at end of file