/** * setConstraint - sets a ZenValidatorContraint on this validator * @param String $field - name of the field to be validated * @param ZenFieldValidator $constraint * @return $this **/ public function setConstraint($fieldName, $constraint) { // remove existing constraint if it already exists if ($this->getConstraint($fieldName, $constraint->class)) { $this->removeConstraint($fieldName, $constraint->class); } $this->constraints[$fieldName][$constraint->class] = $constraint; if ($this->form) { $field = $constraint->setField($this->form->Fields()->dataFieldByName($fieldName)); if ($this->parsleyEnabled) { $field->applyParsley(); } } return $this; }
/** * setConstraint - sets a ZenValidatorContraint on this validator * * @param string $field - name of the field to be validated * @param ZenFieldValidator $constraint * @return $this **/ public function setConstraint($fieldName, $constraint) { // remove existing constraint if it already exists if ($this->getConstraint($fieldName, $constraint->class)) { $this->removeConstraint($fieldName, $constraint->class); } $this->constraints[$fieldName][$constraint->class] = $constraint; if ($this->form) { $dataField = $this->form->Fields()->dataFieldByName($fieldName); $constraint->setField($dataField); if ($this->parsleyEnabled) { // If there is no field, output a clear error message before trying to apply parsley if (!$dataField) { user_error("You have set a constraint on '{$fieldName}' but it does not exist in the FieldList.", E_USER_ERROR); } $constraint->applyParsley(); } } return $this; }