From 61bb16ee2e5f0a66234e1575242169a10fde47b5 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 7 Jul 2006 14:54:15 +0000 Subject: Merge from 3.0 branch till 1253. --- .../Web/UI/WebControls/TRequiredFieldValidator.php | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'framework/Web/UI/WebControls/TRequiredFieldValidator.php') diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php index b8a939ad..c99d9c19 100644 --- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php +++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php @@ -76,22 +76,47 @@ class TRequiredFieldValidator extends TBaseValidator protected function evaluateIsValid() { $control = $this->getValidationTarget(); - $initial = trim($this->getInitialValue()); if($control instanceof TListControl) + return $this->validateListControl($control); + else if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0) + return $this->validateRadioButtonGroup($control); + else + return $this->validateStandardControl($control); + } + + private function validateListControl($control) + { + $initial = trim($this->getInitialValue()); + $count = 0; + foreach($control->getItems() as $item) { - $count = 0; - foreach($control->getItems() as $item) - { - if($item->getSelected() && $item->getValue() != $initial) - $count++; - } - return $count > 0; + if($item->getSelected() && $item->getValue() != $initial) + $count++; } - else + return $count > 0; + } + + private function validateRadioButtonGroup($control) + { + $initial = trim($this->getInitialValue()); + foreach($control->getRadioButtonsInGroup() as $radio) { - $value=$this->getValidationValue($control); - return trim($value)!==$initial || (is_bool($value) && $value); + if($radio->getChecked()) + { + if(strlen($value = $radio->getValue()) > 0) + return $value !== $initial; + else + return true; + } } + return false; + } + + private function validateStandardControl($control) + { + $initial = trim($this->getInitialValue()); + $value=$this->getValidationValue($control); + return trim($value)!==$initial || (is_bool($value) && $value); } /** @@ -105,6 +130,8 @@ class TRequiredFieldValidator extends TBaseValidator $control = $this->getValidationTarget(); if($control instanceof TListControl) $options['TotalItems'] = $control->getItemCount(); + if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0) + $options['GroupName'] = $control->getGroupName(); return $options; } } -- cgit v1.2.3