I’m using the Jstree extension. Validations ‘required, email or url’ are working great, not the same thing for the unique validation (the system seems to bypass it), even if i try to use a custom function to perform it.
Now, I’m trying to validate it “manually” through beforeSave method, but I’ve a problem.
If i use this code, the error doesn’t stop the save process:
public function beforeSave() {
$codice = $this->codice;
$res = $this->findByAttributes(array('codice' => $codice));
if(isset($res)) {
$this->addError('codice', 'Questo codice è già utilizzato.');
}
return parent::beforeSave();
}
If i add “return false”, the save process stops correctly but the error message doesn’t appear:
public function beforeSave() {
$codice = $this->codice;
$res = $this->findByAttributes(array('codice' => $codice));
if(isset($res)) {
$this->addError('codice', 'Questo codice è già utilizzato.');
return false;
}
return parent::beforeSave();
}
What can i do?
Thanks!