diff options
Diffstat (limited to 'framework/Web/UI/WebControls/TRequiredFieldValidator.php')
-rw-r--r-- | framework/Web/UI/WebControls/TRequiredFieldValidator.php | 49 |
1 files changed, 38 insertions, 11 deletions
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;
}
}
|