mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Use cached values for text input
This commit is contained in:
parent
ab63a19aff
commit
6ab976f353
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\CustomField;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Component;
|
||||
|
@ -31,6 +32,16 @@ class CustomFieldSetDefaultValuesForModel extends Component
|
|||
});
|
||||
}
|
||||
|
||||
public function getValueForField(CustomField $field)
|
||||
{
|
||||
return $this->cachedValues->get($field->db_column);
|
||||
}
|
||||
|
||||
public function updateFieldValue($dbColumn, $updatedValue): void
|
||||
{
|
||||
$this->cachedValues->put($dbColumn, $updatedValue);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function model()
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
@if ($this->fields)
|
||||
|
||||
@foreach ($this->fields as $field)
|
||||
<div class="form-group">
|
||||
<div class="form-group" wire:key="field-{{ $field->id }}">
|
||||
|
||||
<label class="col-md-3 control-label{{ $errors->has($field->name) ? ' has-error' : '' }}">{{ $field->name }}</label>
|
||||
|
||||
|
@ -38,7 +38,18 @@
|
|||
@elseif ($field->element == "text")
|
||||
|
||||
|
||||
<input class="form-control" type="text" value="{{ $field->defaultValue($model_id) }}" id="default-value{{ $field->id }}" name="default_values[{{ $field->id }}]">
|
||||
<input
|
||||
class="form-control"
|
||||
type="text"
|
||||
value="{{ $this->getValueForField($field) }}"
|
||||
id="default-value{{ $field->id }}"
|
||||
name="default_values[{{ $field->id }}]"
|
||||
x-on:blur="(e) => $wire.$call(
|
||||
'updateFieldValue',
|
||||
'{{ $field->db_column }}',
|
||||
e.target.value
|
||||
)"
|
||||
/>
|
||||
|
||||
|
||||
@elseif($field->element == "textarea")
|
||||
|
@ -80,11 +91,11 @@
|
|||
Unknown field element: {{ $field->element }}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
@endif
|
||||
|
||||
@endif
|
||||
|
|
Loading…
Reference in a new issue