Skip to content

Commit 029dc8d

Browse files
author
Sofian Mourabit
committed
Finnish image field
1 parent c4a0faf commit 029dc8d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<div class="{{ $field->divClass ?? 'col-6' }}">
22
@include('livewire-forms::fields.label')
3+
34
@if($field->getValue())
45
<img
56
class="{{ $field->class ?? 'img-fluid' }}"
6-
src="{{ optional($field->getValue())->getFormatOrOriginal($field->format)}}"
7+
src="{{ isset($files_[$field->getName()]) ? $files_[$field->getName()]->temporaryUrl() : $field->getValue() }}"
78
alt="{{ $field->altText ?? optional($field->getValue())->name }}"
89
id="{{ $field->getName() }}"
9-
wire:model="files.{{ $field->getName() }}"
1010
>
1111
@endif
12+
<input
13+
type="file"
14+
class="{{ $field->class }}"
15+
id="{{ $field->getName() }}"
16+
name="{{ $field->getName() }}"
17+
placeholder="{{ $field->getLabel() }}"
18+
wire:model="files.{{ $field->getName() }}"
19+
>
1220
@include('livewire-forms::fields.error')
1321
</div>

src/Fields/ImageField.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
namespace Codedor\LivewireForms\Fields;
44

55
use Codedor\Media\Models\Attachment;
6+
use Livewire\TemporaryUploadedFile;
67

78
class ImageField extends Field
89
{
910
public $component = 'livewire-forms::fields.image';
1011

1112
public $value = false;
1213

14+
public $containsFile = true;
15+
1316
public function getValue($doConditionalChecks = false)
1417
{
18+
1519
$value = parent::getValue($doConditionalChecks);
1620

1721
if ($value === '') {
1822
return $value;
1923
}
2024

2125
if (Attachment::find($value)) {
22-
return Attachment::find($value);
26+
return Attachment::find($value)->getFormatOrOriginal($this->format ?? '');
2327
}
2428

2529
return $value;
2630
}
31+
2732
}

0 commit comments

Comments
 (0)