summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/js/validator.js50
-rw-r--r--framework/Web/Javascripts/prado/validation3.js71
-rw-r--r--framework/Web/UI/WebControls/TDataTypeValidator.php13
-rw-r--r--framework/Web/UI/WebControls/TListControlValidator.php132
-rw-r--r--framework/Web/UI/WebControls/TLiteral.php7
-rw-r--r--framework/Web/UI/WebControls/TTable.php2
6 files changed, 165 insertions, 110 deletions
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index 38d8a2a4..8659d2e9 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -353,7 +353,7 @@ validator.manager.updateSummary(validator.group);
this._isObserving[control.id+this.options.ID] = true;
}
},
-trim : function(value)
+_trim : function(value)
{
return typeof(value) == "string" ? value.trim() : "";
},
@@ -393,20 +393,20 @@ getValidationValue : function(control)
{
case 'TDatePicker':
if(control.type == "text")
- return this.trim($F(control));
+ return this._trim($F(control));
else
{
- this.observeDatePickerChanges();
+ this._observeDatePickerChanges();
return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
}
default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
+ if(this._isListControlType())
+ return this._getFirstSelectedListValue();
else
- return this.trim($F(control));
+ return this._trim($F(control));
}
},
-observeDatePickerChanges : function()
+_observeDatePickerChanges : function()
{
if(Prado.Browser().ie)
{
@@ -416,11 +416,11 @@ this.observeChanges(DatePicker.getMonthListControl(this.control));
this.observeChanges(DatePicker.getYearListControl(this.control));
}
},
-getSelectedValuesAndChecks : function(elements, initialValue)
+_getSelectedValuesAndChecks : function(elements, initialValue)
{
var checked = 0;
var values = [];
-var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
+var isSelected = this._isCheckBoxType(elements[0]) ? 'checked' : 'selected';
elements.each(function(element)
{
if(element[isSelected] && element.value != initialValue)
@@ -431,7 +431,7 @@ values.push(element.value);
});
return {'checks' : checked, 'values' : values};
},
-getListElements : function()
+_getListElements : function()
{
switch(this.options.ControlType)
{
@@ -440,7 +440,7 @@ var elements = [];
for(var i = 0; i < this.options.TotalItems; i++)
{
var element = $(this.options.ControlToValidate+"_"+i);
-if(this.isCheckBoxType(element))
+if(this._isCheckBoxType(element))
elements.push(element);
}
return elements;
@@ -457,7 +457,7 @@ default:
return [];
}
},
-isCheckBoxType : function(element)
+_isCheckBoxType : function(element)
{
if(element && element.type)
{
@@ -466,18 +466,18 @@ return type == "checkbox" || type == "radio";
}
return false;
},
-isListControlType : function()
+_isListControlType : function()
{
var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
return list.include(this.options.ControlType);
},
-getFirstSelectedListValue : function()
+_getFirstSelectedListValue : function()
{
var initial = "";
if(typeof(this.options.InitialValue) != "undefined")
initial = this.options.InitialValue;
-var elements = this.getListElements();
-var selection = this.getSelectedValuesAndChecks(elements, initial);
+var elements = this._getListElements();
+var selection = this._getSelectedValuesAndChecks(elements, initial);
return selection.values.length > 0 ? selection.values[0] : initial;
}
}
@@ -493,7 +493,7 @@ return true;
else
{
var a = this.getValidationValue();
-var b = this.trim(this.options.InitialValue);
+var b = this._trim(this.options.InitialValue);
return(a != b);
}
}
@@ -595,16 +595,16 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
evaluateIsValid : function()
{
-var elements = this.getListElements();
+var elements = this._getListElements();
if(elements && elements.length <= 0)
return true;
this.observeListElements(elements);
-var selection = this.getSelectedValuesAndChecks(elements);
+var selection = this._getSelectedValuesAndChecks(elements);
return this.isValidList(selection.checks, selection.values);
},
observeListElements : function(elements)
{
-if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
+if(Prado.Browser().ie && this._isCheckBoxType(elements[0]))
{
var validator = this;
elements.each(function(element)
@@ -640,3 +640,13 @@ required = this.options.Required.split(/,\s*/);
return required;
}
});
+Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+evaluateIsValid : function()
+{
+var value = this.getValidationValue();
+if(value.length <= 0)
+return true;
+return this.convert(this.options.DataType, value) != null;
+}
+});
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index 4c189532..40472e7e 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -667,9 +667,9 @@ Prado.WebUI.TBaseValidator.prototype =
},
/**
- * @return string trims the string value, empty string if value is not string.
+ * @return string _trims the string value, empty string if value is not string.
*/
- trim : function(value)
+ _trim : function(value)
{
return typeof(value) == "string" ? value.trim() : "";
},
@@ -720,25 +720,26 @@ Prado.WebUI.TBaseValidator.prototype =
{
case 'TDatePicker':
if(control.type == "text")
- return this.trim($F(control));
+ return this._trim($F(control));
else
{
- this.observeDatePickerChanges();
+ this._observeDatePickerChanges();
return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
}
default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
+ if(this._isListControlType())
+ return this._getFirstSelectedListValue();
else
- return this.trim($F(control));
+ return this._trim($F(control));
}
},
/**
* Observe changes in the drop down list date picker, IE only.
+ * @private
*/
- observeDatePickerChanges : function()
+ _observeDatePickerChanges : function()
{
if(Prado.Browser().ie)
{
@@ -753,12 +754,13 @@ Prado.WebUI.TBaseValidator.prototype =
* Gets numeber selections and their values.
* @return object returns selected values in <tt>values</tt> property
* and number of selections in <tt>checks</tt> property.
+ * @private
*/
- getSelectedValuesAndChecks : function(elements, initialValue)
+ _getSelectedValuesAndChecks : function(elements, initialValue)
{
var checked = 0;
var values = [];
- var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
+ var isSelected = this._isCheckBoxType(elements[0]) ? 'checked' : 'selected';
elements.each(function(element)
{
if(element[isSelected] && element.value != initialValue)
@@ -774,8 +776,9 @@ Prado.WebUI.TBaseValidator.prototype =
* Gets an array of the list control item input elements, for TCheckBoxList
* checkbox inputs are returned, for TListBox HTML option elements are returned.
* @return array list control option elements.
+ * @private
*/
- getListElements : function()
+ _getListElements : function()
{
switch(this.options.ControlType)
{
@@ -784,7 +787,7 @@ Prado.WebUI.TBaseValidator.prototype =
for(var i = 0; i < this.options.TotalItems; i++)
{
var element = $(this.options.ControlToValidate+"_"+i);
- if(this.isCheckBoxType(element))
+ if(this._isCheckBoxType(element))
elements.push(element);
}
return elements;
@@ -804,8 +807,9 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* @return boolean true if element is of checkbox or radio type.
+ * @private
*/
- isCheckBoxType : function(element)
+ _isCheckBoxType : function(element)
{
if(element && element.type)
{
@@ -817,8 +821,9 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* @return boolean true if control to validate is of some of the TListControl type.
+ * @private
*/
- isListControlType : function()
+ _isListControlType : function()
{
var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
return list.include(this.options.ControlType);
@@ -826,14 +831,15 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* @return string gets the first selected list value, initial value if none found.
+ * @private
*/
- getFirstSelectedListValue : function()
+ _getFirstSelectedListValue : function()
{
var initial = "";
if(typeof(this.options.InitialValue) != "undefined")
initial = this.options.InitialValue;
- var elements = this.getListElements();
- var selection = this.getSelectedValuesAndChecks(elements, initial);
+ var elements = this._getListElements();
+ var selection = this._getSelectedValuesAndChecks(elements, initial);
return selection.values.length > 0 ? selection.values[0] : initial;
}
}
@@ -862,7 +868,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
else
{
var a = this.getValidationValue();
- var b = this.trim(this.options.InitialValue);
+ var b = this._trim(this.options.InitialValue);
return(a != b);
}
}
@@ -1099,13 +1105,13 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
*/
evaluateIsValid : function()
{
- var elements = this.getListElements();
+ var elements = this._getListElements();
if(elements && elements.length <= 0)
return true;
this.observeListElements(elements);
- var selection = this.getSelectedValuesAndChecks(elements);
+ var selection = this._getSelectedValuesAndChecks(elements);
return this.isValidList(selection.checks, selection.values);
},
@@ -1114,7 +1120,7 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
*/
observeListElements : function(elements)
{
- if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
+ if(Prado.Browser().ie && this._isCheckBoxType(elements[0]))
{
var validator = this;
elements.each(function(element)
@@ -1165,6 +1171,25 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
}
});
-
-
+/**
+ * TDataTypeValidator verifies if the input data is of the type specified
+ * by <tt>DataType</tt> option.
+ * The following data types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Date</b> A date data type.
+ * - <b>String</b> A string data type.
+ * For <b>Date</b> type, the option <tt>DateFormat</tt>
+ * will be used to determine how to parse the date string.
+ */
+Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ evaluateIsValid : function()
+ {
+ var value = this.getValidationValue();
+ if(value.length <= 0)
+ return true;
+ return this.convert(this.options.DataType, value) != null;
+ }
+});
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
@@ -99,6 +99,19 @@ class TDataTypeValidator extends TBaseValidator
}
/**
+ * 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.
* The validation always succeeds if ControlToValidate is not specified
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 @@
<?php
-
/**
* TListControlValidator class file
*
@@ -10,7 +9,7 @@
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
*/
-
+
/**
* Using TBaseValidator class
*/
@@ -18,9 +17,9 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
/**
* TListControlValidator class.
- *
+ *
* TListControlValidator checks the number of selection and their values
- * for a <b>TListControl that allows multiple selection</b>.
+ * for a <b>TListControl that allows multiple selection</b>.
*
* 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');
* <com:TListItem Text="item3" Value="value3" />
* </com:TListBox>
*
- * <com:TRequiredListValidator
+ * <com:TRequiredListValidator
* ControlToValidate="listbox"
- * MinSelection="2"
+ * MinSelection="2"
* ErrorMessage="Please select at least 2" />
* </code>
* - "value1" must be selected <b>and</b> at least 1 other
@@ -47,14 +46,14 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* <com:TCheckBoxList ID="checkboxes">
* <com:TListItem Text="item1" Value="value1" />
* <com:TListItem Text="item2" Value="value2" />
- * <com:TListItem Text="item3" Value="value3" />
+ * <com:TListItem Text="item3" Value="value3" />
* </com:TCheckBoxList>
*
- * <com:TRequiredListValidator
+ * <com:TRequiredListValidator
* ControlToValidate="checkboxes"
* RequiredSelections="value1"
* MinSelection="2"
- * ErrorMessage="Please select 'item1' and at least 1 other" />
+ * ErrorMessage="Please select 'item1' and at least 1 other" />
* </code>
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail.com>
@@ -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');
* <com:TTableCell Text="content" />
* <com:TTableCell Text="content" />
* </com:TTableRow>
- * <com:TTable>
+ * </com:TTable>
* </code>
* The above can also be accomplished in code as follows,
* <code>