Hi,
the updated($field) method gives you only the currently updated field (not an array of all fields).
I think you need to add some logic to keep track of the current validation state for each field - Livewire won't do that for you automatically (at least I don't know how)
See the code below.
The idea is to have an array which holds an entry for each field when the field is validated.
validateOnly($field)returns an array when the validation passes.
The array has one key ($field) and the value is the input from the field.
If the validation does not pass you get an empty array as a return value.
So in updated($field) we store that in $this->validated_fields.
In updating($field)we need to clear the result from the last validationOnly call or else Livewire won't forget the last value. This means when the validation passes once it is never updated - not even when the user removes the input from the field. Therefor we need to clear it every time.
Then in render()we check if our validated_fields array has 3 entries (it means all 3 fields are validated) and set the $disabledvariable.
Hope this helps!
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Support\Arr;
class ExampleForm extends Component
{
public $name = '';
public $email = '';
public $password = '';
public $validated_fields;
public $disabled = true;
protected $rules = [
'name' => 'required|min:6',
'email' => 'required|numeric',
'password' => 'required|min:3',
];
public function mount()
{
$this->validated_fields = [];
}
public function updating($field)
{
Arr::pull($this->validated_fields, $field);
}
public function updated($field)
{
$v = $this->validateOnly($field);
$this->validated_fields[$field] = Arr::get($v, $field, false);
}
public function submitForm()
{
$validatedData = $this->validate();
}
public function render()
{
$this->disabled = count($this->validated_fields) <> 3;
return view('livewire.example-form');
}
}