diff options
author | wei <> | 2006-04-25 01:00:08 +0000 |
---|---|---|
committer | wei <> | 2006-04-25 01:00:08 +0000 |
commit | c84f3e19b54cf54f525f4b2d158696ae32d1bf60 (patch) | |
tree | 60720fba29ef72175db47dd3cd4b74d8bbed605b /framework/Web/UI/WebControls | |
parent | 09edc6590523e26fffbf32f7b0e7958c166f7537 (diff) |
Add TListControlValidator. Update client-side validators, datepicker.js, colorpicker.js.
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r-- | framework/Web/UI/WebControls/TBaseValidator.php | 6 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCheckBox.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCheckBoxList.php | 14 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCompareValidator.php | 16 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataGridColumn.php | 30 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataTypeValidator.php | 8 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDatePicker.php | 45 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/THtmlArea.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 52 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControlValidator.php | 214 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRangeValidator.php | 41 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRequiredFieldValidator.php | 30 |
12 files changed, 373 insertions, 89 deletions
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index c5b5e7a5..adbc85ae 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -131,6 +131,7 @@ abstract class TBaseValidator extends TLabel implements IValidator */ protected function getClientScriptOptions() { + $control = $this->getValidationTarget(); $options['ID'] = $this->getClientID(); $options['FormID'] = $this->getPage()->getForm()->getClientID(); $options['Display'] = $this->getDisplay(); @@ -141,8 +142,9 @@ abstract class TBaseValidator extends TLabel implements IValidator $options['FocusElementID'] = $this->getFocusElementID(); } $options['ValidationGroup'] = $this->getValidationGroup(); - $options['ControlToValidate'] = $this->getValidationTarget()->getClientID(); + $options['ControlToValidate'] = $control->getClientID(); $options['ControlCssClass'] = $this->getControlCssClass(); + $options['ControlType'] = get_class($control); return $options; } @@ -163,7 +165,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $manager['FormID'] = $formID; $options = TJavaScript::encode($manager); $scripts->registerPradoScript('validator'); - $scripts->registerEndScript($scriptKey, "new Prado.Validation({$options});"); + $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); } if($this->getEnableClientScript()) $this->registerClientScriptValidator(); diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index ff7f57f7..681c8748 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -340,7 +340,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl if($clientID!=='')
$writer->addAttribute('id',$clientID);
$writer->addAttribute('type','checkbox');
- if(($value=$this->getValueAttribute())!=='')
+ if(($value = $this->getValueAttribute()) !== '')
$writer->addAttribute('value',$value);
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
@@ -378,4 +378,4 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl }
-?>
\ No newline at end of file +?>
diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index 8a106b46..de332897 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -47,7 +47,7 @@ Prado::using('System.Web.UI.WebControls.TCheckBox'); * @package System.Web.UI.WebControls
* @since 3.0
*/
-class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler
+class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable
{
private $_repeatedControl;
private $_isEnabled;
@@ -309,7 +309,7 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont if($item->getEnabled())
{
$checked=isset($values[$key]);
- if($item->getSelected()!=$checked)
+ if($item->getSelected()!==$checked)
{
$item->setSelected($checked);
if(!$this->_changedEventRaised)
@@ -381,6 +381,16 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont $this->setTabIndex($tabIndex);
}
}
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getSelectedValue();
+ }
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index 172e472f..b5ebd3ab 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -31,7 +31,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * type before the comparison operation is performed. The following value 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>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The format can be specified by the
* {@link setDateFormat DateFormat} property
* - <b>String</b> A string data type.
@@ -56,12 +55,13 @@ class TCompareValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Date, String) 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','Currency','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
}
/**
@@ -188,16 +188,6 @@ class TCompareValidator extends TBaseValidator return array(intval($value1), intval($value2));
case 'Float':
return array(floatval($value1), floatval($value2));
- case 'Currency':
- if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value1,$matches))
- $value1=floatval($matches[0]);
- else
- $value1=0;
- if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value2,$matches))
- $value2=floatval($matches[0]);
- else
- $value2=0;
- return array($value1, $value2);
case 'Date':
$dateFormat = $this->getDateFormat();
if($dateFormat!=='')
diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php index de9d9d5c..e43b4895 100644 --- a/framework/Web/UI/WebControls/TDataGridColumn.php +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -11,7 +11,7 @@ */
/**
- * Includes TDataFieldAccessor class
+ * Includes TDataFieldAccessor and TDataValueFormatter classes
*/
Prado::using('System.Util.TDataFieldAccessor');
@@ -331,17 +331,37 @@ abstract class TDataGridColumn extends TApplicationComponent }
/**
- * Formats the text value according to format string.
- * This method invokes the {@link sprintf} to do string formatting.
+ * Formats the text value according to a format string.
* If the format string is empty, the original value is converted into
* a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
* @param string format string
- * @param mixed the data associated with the cell
+ * @param mixed the data to be formatted
* @return string the formatted result
*/
protected function formatDataValue($formatString,$value)
{
- return $formatString===''?TPropertyValue::ensureString($value):sprintf($formatString,$value);
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
}
}
diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index 81c23ce4..d78be7bf 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -23,7 +23,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * 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>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type.
* - <b>String</b> A string data type.
* For <b>Date</b> type, the property {@link setDateFormat DateFormat}
@@ -46,12 +45,13 @@ class TDataTypeValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Date, String) 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','Currency','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
}
/**
@@ -85,8 +85,6 @@ class TDataTypeValidator extends TBaseValidator return preg_match('/^[-+]?[0-9]+$/',trim($value));
case 'Float':
return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
- case 'Currency':
- return preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
case 'Date':
$dateFormat = $this->getDateFormat();
if(strlen($dateFormat))
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index c6a2345b..02386515 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -245,17 +245,16 @@ class TDatePicker extends TTextBox /**
* @return integer current selected date from the date picker as timestamp.
*/
- public function getDate()
+ public function getTimeStamp()
{
- $date = $this->getDateFromText();
- return $date[0];
+ return $this->getTimeStampFromText();
}
/**
* Sets the date for the date picker using timestamp.
* @param integer time stamp for the date picker
*/
- public function setDate($value)
+ public function setTimeStamp($value)
{
$date = TPropertyValue::ensureInteger($value);
$formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
@@ -264,6 +263,34 @@ class TDatePicker extends TTextBox }
/**
+ * @return string the date string.
+ */
+ public function getDate()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * @param string date string
+ */
+ public function setDate($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return integer the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ if($this->getText() === '')
+ return '';
+ return $this->getTimeStamp();
+ }
+
+ /**
* Publish the date picker Css asset files.
*/
public function onPreRender($param)
@@ -396,6 +423,7 @@ class TDatePicker extends TTextBox $date = $this->getLocalizedCalendarInfo();
$options['MonthNames'] = TJavaScript::encode($date->getMonthNames(),false);
+ $options['AbbreviatedMonthNames'] = TJavaScript::encode($date->getAbbreviatedMonthNames(),false);
$options['ShortWeekDayNames'] = TJavaScript::encode($date->getAbbreviatedDayNames(),false);
return $options;
@@ -439,7 +467,8 @@ class TDatePicker extends TTextBox $writer->addAttribute('class', $class);
$writer->renderBeginTag('span');
- $date = $this->getDateFromText();
+ $date = @getdate($this->getTimeStampFromText());
+
$this->renderCalendarSelections($writer, $date);
//render a hidden input field
@@ -481,9 +510,9 @@ class TDatePicker extends TTextBox /**
* Gets the date from the text input using TSimpleDateFormatter
- * @return array current selected date
+ * @return integer current selected date timestamp
*/
- protected function getDateFromText()
+ protected function getTimeStampFromText()
{
$pattern = $this->getDateFormat();
$pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
@@ -559,7 +588,7 @@ class TDatePicker extends TTextBox case 'MMM':
case 'MM': return $info->getAbbreviatedMonthNames();
case 'M':
- $array = array(); for($i=1;$i<=12;$i++) $array[$i] = $i;
+ $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i;
return $array;
default : return $info->getMonthNames();
}
diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 7e47d638..8e5fcd16 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -315,7 +315,7 @@ class THtmlArea extends TTextBox //default the variant to "en"
if(count($variants) == 0)
{
- if($empty($culture))
+ if(empty($culture))
return 'en';
$variants[] = strtolower($culture);
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index 37c232e6..1c615edc 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -11,18 +11,13 @@ */
/**
- * Includes TDataBoundControl class
+ * Includes the supporting classes
*/
Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-/**
- * Includes TAttributeCollection class
- */
Prado::using('System.Collections.TAttributeCollection');
-/**
- * Includes TDataFieldAccessor class
- */
Prado::using('System.Util.TDataFieldAccessor');
+
/**
* TListControl class
*
@@ -74,8 +69,8 @@ Prado::using('System.Util.TDataFieldAccessor'); * to 'name' and 'age' will make the first item's text be 'John', value be 31,
* the second item's text be 'Cary', value be 28, and so on.
* The {@link setDataTextFormatString DataTextFormatString} property may be further
- * used to format how the item should be displayed. The formatting function is
- * the sprintf() PHP function.
+ * used to format how the item should be displayed. See {@link formatDataValue()}
+ * for an explanation of the format string.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -192,7 +187,7 @@ abstract class TListControl extends TDataBoundControl $text=$object;
$item->setValue("$key");
}
- $item->setText($textFormat===''?$text:sprintf($textFormat,$text));
+ $item->setText($this->formatDataValue($textFormat,$text));
$items->add($item);
}
// SelectedValue or SelectedIndex may be set before databinding
@@ -329,9 +324,10 @@ abstract class TListControl extends TDataBoundControl /**
* Sets data text format string.
- * The format string is used in sprintf() to format the Text property value
+ * The format string is used in {@link TDataValueFormatter::format()} to format the Text property value
* of each item in the list control.
* @param string the formatting string used to control how data bound to the list control is displayed.
+ * @see TDataValueFormatter::format()
*/
public function setDataTextFormatString($value)
{
@@ -585,6 +581,40 @@ abstract class TListControl extends TDataBoundControl }
}
}
+
+ /**
+ * Formats the text value according to a format string.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
+ * @param string format string
+ * @param mixed the data to be formatted
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
+ }
}
/**
diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php new file mode 100644 index 00000000..9264e891 --- /dev/null +++ b/framework/Web/UI/WebControls/TListControlValidator.php @@ -0,0 +1,214 @@ +<?php
+
+/**
+ * TListControlValidator class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+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>.
+ *
+ * You can specify the minimum or maximum (or both) number of selections
+ * required using the {@link setMinSelection MinSelection} and
+ * {@link setMaxSelection MaxSelection} properties, respectively. In addition,
+ * you can specify a comma separated list of required selected values via the
+ * {@link setRequiredSelections RequiredSelections} property.
+ *
+ * Examples
+ * - At least two selections
+ * <code>
+ * <com:TListBox ID="listbox" SelectionMode="Multiple">
+ * <com:TListItem Text="item1" Value="value1" />
+ * <com:TListItem Text="item2" Value="value2" />
+ * <com:TListItem Text="item3" Value="value3" />
+ * </com:TListBox>
+ *
+ * <com:TRequiredListValidator
+ * ControlToValidate="listbox"
+ * MinSelection="2"
+ * ErrorMessage="Please select at least 2" />
+ * </code>
+ * - "value1" must be selected <b>and</b> at least 1 other
+ * <code>
+ * <com:TCheckBoxList ID="checkboxes">
+ * <com:TListItem Text="item1" Value="value1" />
+ * <com:TListItem Text="item2" Value="value2" />
+ * <com:TListItem Text="item3" Value="value3" />
+ * </com:TCheckBoxList>
+ *
+ * <com:TRequiredListValidator
+ * ControlToValidate="checkboxes"
+ * RequiredSelections="value1"
+ * MinSelection="2"
+ * ErrorMessage="Please select 'item1' and at least 1 other" />
+ * </code>
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TListControlValidator extends TBaseValidator
+{
+ /**
+ * @return int min number of selections
+ */
+ function getMinSelection()
+ {
+ return $this->getViewState('MinSelection','');
+ }
+
+ /**
+ * @param int minimum number of selections.
+ */
+ function setMinSelection($value)
+ {
+ $this->setViewState('MinSelection',$value,'');
+ }
+
+ /**
+ * @return int max number of selections
+ */
+ function getMaxSelection()
+ {
+ return $this->getViewState('MaxSelection','');
+ }
+
+ /**
+ * @param int max number of selections.
+ */
+ function setMaxSelection($value)
+ {
+ $this->setViewState('MaxSelection',$value,'');
+ }
+
+ /**
+ * Get a comma separated list of required selected values.
+ * @return string comma separated list of required values.
+ */
+ 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.
+ */
+ 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()
+ {
+ $control=$this->getValidationTarget();
+
+ $exists = true;
+ list($count, $values) = $this->getSelection($control);
+ $required = $this->getRequiredValues();
+
+ //if required, check the values
+ if(!empty($required))
+ {
+ if(count($values) < 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);
+ }
+
+ /**
+ * @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++;
+ $values[] = $item->getValue();
+ }
+ }
+ return array($count, $values);
+ }
+
+ /**
+ * @return array list of required values.
+ */
+ protected function getRequiredValues()
+ {
+ $required = array();
+ $string = $this->getRequiredSelections();
+ if(!empty($string))
+ $required = preg_split('/,\s*/', $string);
+ return $required;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $control = $this->getValidationTarget();
+
+ if(!$control instanceof TListControl)
+ {
+ throw new TConfigurationException(
+ '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);
+ $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/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php index 56cc16bc..b7387522 100644 --- a/framework/Web/UI/WebControls/TRangeValidator.php +++ b/framework/Web/UI/WebControls/TRangeValidator.php @@ -29,7 +29,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * operation is performed. The following value 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>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The date format can be specified by
* setting {@link setDateFormat DateFormat} property, which must be recognizable
* by {@link TSimpleDateFormatter}. If the property is not set,
@@ -87,13 +86,13 @@ class TRangeValidator extends TBaseValidator }
/**
- * Sets the data type (Integer, Float, Currency, Date, String) that the values
- * being compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Date, String) 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','Currency','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
}
/**
@@ -131,8 +130,6 @@ class TRangeValidator extends TBaseValidator return $this->isValidInteger($value);
case 'Float':
return $this->isValidFloat($value);
- case 'Currency':
- return $this->isValidCurrency($value);
case 'Date':
return $this->isValidDate($value);
default:
@@ -179,38 +176,6 @@ class TRangeValidator extends TBaseValidator }
/**
- * Determine if the value is a valid currency range,
- * @param string currency value
- * @return boolean true if within range.
- */
- protected function isValidCurrency($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
- $valid=true;
- $value = $this->getCurrencyValue($value);
- if($minValue!=='')
- $valid=$valid && ($value>= $this->getCurrencyValue($minValue));
- if($maxValue!=='')
- $valid=$valid && ($value<= $this->getCurrencyValue($minValue));
- return $valid;
- }
-
- /**
- * Parse the string into a currency value, return the float value of the currency.
- * @param string currency as string
- * @return float currency value.
- */
- protected function getCurrencyValue($value)
- {
- if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value,$matches))
- return floatval($matches[0]);
- else
- return 0.0;
- }
-
- /**
* Determine if the date is within the specified range.
* Uses pradoParseDate and strtotime to get the date from string.
* @param string date as string to validate
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php index ddbb12c8..04e333eb 100644 --- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php +++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php @@ -21,6 +21,9 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * 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.
+ *
+ * Validation will also succeed if input is of TListControl type and the number
+ * of selected values different from the initial value is greater than zero.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -53,12 +56,32 @@ class TRequiredFieldValidator extends TBaseValidator * 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.
+ *
+ * Validation will also succeed if input is of TListControl type and the
+ * number of selected values different from the initial value is greater
+ * than zero.
+ *
* @return boolean whether the validation succeeds
*/
protected function evaluateIsValid()
{
- $value=$this->getValidationValue($this->getValidationTarget());
- return trim($value)!==trim($this->getInitialValue()) || (is_bool($value) && $value);
+ $control = $this->getValidationTarget();
+ $initial = trim($this->getInitialValue());
+ if($control instanceof TListControl)
+ {
+ $count = 0;
+ foreach($control->getItems() as $item)
+ {
+ if($item->getSelected() && $item->getValue() != $initial)
+ $count++;
+ }
+ return $count > 0;
+ }
+ else
+ {
+ $value=$this->getValidationValue($control);
+ return trim($value)!==$initial || (is_bool($value) && $value);
+ }
}
/**
@@ -69,6 +92,9 @@ class TRequiredFieldValidator extends TBaseValidator {
$options = parent::getClientScriptOptions();
$options['InitialValue']=$this->getInitialValue();
+ $control = $this->getValidationTarget();
+ if($control instanceof TListControl)
+ $options['TotalItems'] = $control->getItemCount();
return $options;
}
}
|