Real time validation not working as expected

I am working on a Laravel/Livewire multi-tenant application that has a form with 4 elements on it a name, email, and role with a submit button. The name should be unique to the tenants and the email should be unique to the application. The 2 elements that are doing real time validation are working (sort of) but everytime one of the elements lose focus on the page the error goes away. This behaviour seems off to me. I would expect the error message to stay on all elements that are in error.

Any help appreciated.
Kulmacet

Here is some code from the livewire component page but I’m not sure this is where the problem is

(...)
public function updated()
    {
        $this->validate([
            'name' => new userTenantNameRule,
            'email' => 'unique:users',
        ]);
    }
(...)

and if you use the validateOnly inside updated($name) like

$this->validateOnly($name, [
     'name' => new userTenantNameRule,
     'email' => 'unique:users',
]);

???. This is like docs said about real time validation

Hey, @kulmacet

You must use validateOnly method not validate and pass the fields


public function updated($fields)
{
  $this->validateOnly($fields, [ ...]);
}  

For more info take a look here:

Thank you for the reply but it does not give the desired behavior.

Can you share the blade file of that component?

Here is that component

<?php

namespace App\Http\Livewire\Users;

use App\Models\Element;
use App\Models\User;
use App\Rules\UserTenantNameRule;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Livewire\Component;

class UserCreate extends Component
{
    public $name = '';
    public $email = '';
    public $role_id = '';
    public $selects;

    protected $rules = [
        'name' => 'required',
        'email' => 'required|email',
        'role' => 'required',
    ];

    public function updated($field)
    {
        //
    }

    public function create()
    {
        //Test that name is not used in Tenant
        $data = $this->validate([
            'name' => ['required', 'min:8', new UserTenantNameRule()],
            'email' => ['required', 'email', 'unique:users'],
            'role_id' => ['required'],
        ]);
        
        $role_id = Element::idByDataid($data['role_id']);

        User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'role_id' => $role_id,
            'password' => Hash::make('Password'),
        ]);

        return redirect('/users');
    }

    public function render()
    {
        return view('livewire.users.user-create');
    }
}

and the

user-create

blade? Can you share it with us?