Fix multilple file input bug once and for all
This commit is contained in:
@@ -1,21 +1,7 @@
|
|||||||
@props(['name', 'type' => 'text', 'multiple' => false])
|
@props(['name'])
|
||||||
|
|
||||||
@if($type === 'file' && $multiple)
|
@error($name)
|
||||||
@foreach ($errors->get( rtrim($name, []) . '.*') as $messages)
|
<p class="text-sm text-error mt-1">
|
||||||
@foreach ($messages as $message)
|
{{ $message }}
|
||||||
<p class="text-sm text-error mt-1">
|
</p>
|
||||||
{{ $message }}
|
@enderror
|
||||||
</p>
|
|
||||||
@endforeach
|
|
||||||
@endforeach
|
|
||||||
@else
|
|
||||||
@php
|
|
||||||
$message = $errors->first($name);
|
|
||||||
@endphp
|
|
||||||
|
|
||||||
@if($message)
|
|
||||||
<p class="text-sm text-error mt-1">
|
|
||||||
{{ $message }}
|
|
||||||
</p>
|
|
||||||
@endif
|
|
||||||
@endif
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
@if (! $isLivewire && ! empty($resolvedValue))
|
@if (! $isLivewire && ! empty($resolvedValue))
|
||||||
value="{{ $resolvedValue }}"
|
value="{{ $resolvedValue }}"
|
||||||
@endif
|
@endif
|
||||||
|
@if($multiple) multiple @endif
|
||||||
|
|
||||||
{{ $attributes->merge(['class' => $inputClasses]) }}
|
{{ $attributes->merge(['class' => $inputClasses]) }}
|
||||||
/>
|
/>
|
||||||
@@ -24,5 +25,17 @@
|
|||||||
<x-sk::form.help>{{ $help }}</x-sk::form.help>
|
<x-sk::form.help>{{ $help }}</x-sk::form.help>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<x-sk::form.error :$name :$type @isset($multiple) :multiple="$multiple" @endisset />
|
|
||||||
|
|
||||||
|
@if($type === 'file' && $multiple)
|
||||||
|
@foreach($errors->get(rtrim($name, '[]') . '.*') as $error)
|
||||||
|
<p class="text-sm text-error mt-1">
|
||||||
|
{{ $error[0] }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
<x-sk::form.error :name="$name" />
|
||||||
|
@endif
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -38,8 +38,22 @@ trait InteractsWithFormField
|
|||||||
|
|
||||||
public function render(): View
|
public function render(): View
|
||||||
{
|
{
|
||||||
|
$multipleInputFileHasError = false;
|
||||||
|
|
||||||
if (session('errors')?->has($this->name)) {
|
if(isset($this->type) && isset($this->multiple)) {
|
||||||
|
if($this->type === 'file' && $this->multiple) {
|
||||||
|
if(session('errors') !== null)
|
||||||
|
{
|
||||||
|
foreach (session('errors')->getMessages() as $key => $error) {
|
||||||
|
if (str_starts_with($key, rtrim($this->name, '[]') . '.')) {
|
||||||
|
$multipleInputFileHasError = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(session('errors')?->has($this->name) || $multipleInputFileHasError) {
|
||||||
$this->inputClasses .= ' input-error';
|
$this->inputClasses .= ' input-error';
|
||||||
}
|
}
|
||||||
if($this->readonly)
|
if($this->readonly)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Input extends Component
|
|||||||
* @param bool $required
|
* @param bool $required
|
||||||
* @param bool $disabled
|
* @param bool $disabled
|
||||||
* @param bool $readonly Will act as disabled, but keep an HTML-sendable value
|
* @param bool $readonly Will act as disabled, but keep an HTML-sendable value
|
||||||
|
* @param bool $multiple If true, the input will be a multiple file upload input.
|
||||||
* @param string $gridLayout The form section component offers a grid of 12 columns. Adjust this parameter as needed.
|
* @param string $gridLayout The form section component offers a grid of 12 columns. Adjust this parameter as needed.
|
||||||
* @param mixed|null $value
|
* @param mixed|null $value
|
||||||
* @param mixed|null $model If $model->$name exists, you can just set the model instead of a value.
|
* @param mixed|null $model If $model->$name exists, you can just set the model instead of a value.
|
||||||
@@ -33,6 +34,7 @@ class Input extends Component
|
|||||||
public bool $required = false,
|
public bool $required = false,
|
||||||
public bool $disabled = false,
|
public bool $disabled = false,
|
||||||
public bool $readonly = false,
|
public bool $readonly = false,
|
||||||
|
public bool $multiple = false,
|
||||||
public string $gridLayout = '',
|
public string $gridLayout = '',
|
||||||
public mixed $value = null,
|
public mixed $value = null,
|
||||||
public mixed $model = null,
|
public mixed $model = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user