Laravel Livewire errors are not cleared
Solution 1
According to docs https://laravel-livewire.com/docs/input-validation,
You need to reset the validations whenever you want
Direct Error Message Manipulation The validate() and validateOnly() method should handle most cases, but sometimes you may want direct control over Livewire's internal ErrorBag.
Livewire provides a handful of methods for you to directly manipulate the ErrorBag.
From anywhere inside a Livewire component class, you can call the following methods:
$this->addError('email', 'The email field is invalid.'); // Quickly add a validation message to the error bag. $this->resetErrorBag(); $this->resetValidation(); // These two methods do the same thing. The clear the error bag. // If you only want to clear errors for one key, you can use: $this->resetValidation('email'); $this->resetErrorBag('email'); $errors = $this->getErrorBag(); // This will give you full access to the error bag, // allowing you to do things like this: $errors->add('some-key', 'Some message');
HINT
I am using the reset methods on hydrate function like following
...
public function hydrate()
{
$this->resetErrorBag();
$this->resetValidation();
}
...
Solution 2
You should reset the public properties by using the livewire's reset
method. Delete your $this->clear()
method definition and replace it with the following:
$this->reset('name', 'street', 'city', 'dueAmount');

Author by
Admin
Updated on June 16, 2022Comments
-
Admin about 2 months