1

I am trying out Livewire's instant authentication which seems to work fine for other inputs but array fields. Wondering how I could show the error messages for array inputs. Blade code

<input type="tel" pattern="[0-9]+" minlength="6" wire:model="contact_phone.{{$index}}"
       class="form-control {{ $errors->has('contact_phone.*') ? ' is-invalid' : '' }} " required>
<div>@error('contact_phone') <span class="error text-danger small">{{ $message }}</span> @enderror</div>   

Validation

public function updated($field)
    {
        $this->validateOnly($field, [ 
            'contact_phone' => 'required|array|min:1',
            'contact_phone.*' => 'required|string|min:3',
        ]);

    }

Following this doc

2
  • Reuben, your input is for "contact_phone" and your validation is for "contact_name"; maybe this is your issue? Otherwise, please post the correct code, thanks. Commented Apr 7, 2020 at 5:32
  • Sorry, I edited the question now Commented Apr 7, 2020 at 14:05

1 Answer 1

1

This is how I finally got it to work. The key was to access the index of the specific array input in @error directive.

<input type="tel" pattern="[0-9]+" minlength="6" wire:model.lazy="contact_phone.{{$index}}"
       class="form-control {{ $errors->has('contact_phone.'.$index) ? ' is-invalid' : '' }} " required>
<div>@error('contact_phone.{{$index}}')
    <span class="error text-danger small">{{ $message }}</span> @enderror
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.