【问题标题】:Livewire Array Instant ValidationLivewire 阵列即时验证
【发布时间】:2020-07-04 20:54:01
【问题描述】:

我正在尝试 Livewire 的即时身份验证,它似乎适用于除数组字段之外的其他输入。想知道如何显示数组输入的错误消息。 刀片代码

<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>   

验证

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

    }

关注这个doc

【问题讨论】:

  • Reuben,您的输入是针对“contact_phone”,您的验证是针对“contact_name”;也许这是你的问题?否则,请发布正确的代码,谢谢。
  • 抱歉,我现在编辑了问题

标签: laravel validation laravel-6 laravel-livewire


【解决方案1】:

这就是我最终让它工作的方式。关键是在@error 指令中访问特定数组输入的索引。

<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>

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 2021-05-16
    • 2021-02-06
    • 2021-05-12
    • 2021-09-12
    • 2021-06-12
    • 2021-01-14
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多