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. If the input is of TListControl type and has a {@link TListControl::setPromptValue PromptValue} set, it will be automatically considered as the validator's {@link setInitialValue InitialValue}.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends TBaseValidator
 public function testGetEmptyInitialValue()
 {
     $validator = new TRequiredFieldValidator();
     try {
         $value = $validator->getInitialValue();
     } catch (TConfigurationException $e) {
         //since prado 3.2.2 you need to set at least ControlToValidate
         $value = '';
     }
     $this->assertEquals('', $value);
 }
Ejemplo n.º 2
0
 protected function createRequiredValidator($container, $column, $record)
 {
     $val = new TRequiredFieldValidator();
     $val->setErrorMessage('*');
     $val->setControlCssClass('required-input');
     $val->setCssClass('required');
     $val->setControlToValidate(self::DEFAULT_ID);
     $val->setValidationGroup($this->getParent()->getValidationGroup());
     $val->setDisplay(TValidatorDisplayStyle::Dynamic);
     $container->Controls[] = $val;
     return $val;
 }