Inheritance: extends ZenValidatorConstraint
 public function testSetGetRemoveContraints()
 {
     $zv = $this->Form()->getValidator();
     // set/get
     $zv->setConstraints(array('Title' => array(Constraint_required::create(), Constraint_length::create('min', 4)), 'Subtitle' => Constraint_required::create()));
     $this->assertTrue(count($zv->getConstraints('Title')) == 2);
     $this->assertTrue(count($zv->getConstraints('Subtitle')) == 1);
     // remove
     $zv->removeConstraints('Title');
     $zv->removeConstraints('Subtitle');
     $this->assertTrue(count($zv->getConstraints('Title')) == 0);
     $this->assertTrue(count($zv->getConstraints('Subtitle')) == 0);
 }
 public function testZenValdWithRule3()
 {
     $form = $this->Form();
     $zv = $form->getValidator();
     $zv->setConstraint('SN', Constraint_required::create(), 'IsTrue == True');
     $zv->setConstraint('Name', Constraint_required::create(), '!(IsTrue == True)');
     // $data['IsTrue'] = '';
     $data['SN'] = '';
     $data['Name'] = '';
     $zv->php($data);
     $errors = $zv->getErrors();
     $this->assertTrue(sizeof($errors) == 1 && $errors[0]['fieldName'] == 'Name');
 }
 /**
  * A quick way of adding required constraints to a number of fields
  * @param array $fieldNames - can be either indexed array of fieldnames, or associative array of fieldname => message
  * @return this
  */
 public function addRequiredFields($fields)
 {
     if (ArrayLib::is_associative($fields)) {
         foreach ($fields as $k => $v) {
             $constraint = Constraint_required::create();
             if ($v) {
                 $constraint->setMessage($v);
             }
             $this->setConstraint($k, $constraint);
         }
     } else {
         foreach ($fields as $field) {
             $this->setConstraint($field, Constraint_required::create());
         }
     }
     return $this;
 }