yii\base\Model::clearErrors PHP Method

clearErrors() public method

Removes errors for all attributes or a single attribute.
public clearErrors ( string $attribute = null )
$attribute string attribute name. Use null to remove errors for all attributes.
    public function clearErrors($attribute = null)
    {
        if ($attribute === null) {
            $this->_errors = [];
        } else {
            unset($this->_errors[$attribute]);
        }
    }

Usage Example

 /**
  * @param Event $event event parameter.
  */
 public function afterValidate($event)
 {
     if (!$this->getIsNeedValidate()) {
         $this->owner->clearErrors($this->attribute);
     }
     if ($this->owner->hasErrors()) {
         $this->addAttempt();
     } else {
         $this->removeAttempts();
     }
 }