Possible fix for asset model editing when no custom fieldset is associated

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2021-11-15 21:09:35 -08:00
parent 476e17055b
commit bbb0d1be17
2 changed files with 15 additions and 4 deletions

View file

@ -19,15 +19,24 @@ class CustomFieldSetDefaultValuesForModel extends Component
{
$this->model = AssetModel::find($this->model_id); // It's possible to do some clever route-model binding here, but let's keep it simple, shall we?
$this->fieldset_id = $this->model->fieldset_id;
$this->fields = null;
if ($fieldset = CustomFieldset::find($this->fieldset_id)) {
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
$this->add_default_values = ( $this->model->defaultValues->count() > 0);
}
$this->add_default_values = ($this->model->defaultValues->count() > 0);
}
public function updatedFieldsetId()
{
if (CustomFieldset::find($this->fieldset_id)) {
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
}
}
public function render()
{
return view('livewire.custom-field-set-default-values-for-model');

View file

@ -12,9 +12,10 @@
</span>
</div>
</div>
@if( $this->add_default_values ) {{-- 'if the checkbox is enabled *AND* there are more than 0 fields in the fieldsset' --}}
@if ($this->add_default_values ) {{-- 'if the checkbox is enabled *AND* there are more than 0 fields in the fieldsset' --}}
<div>
<div class="form-group">
@if ($fields)
@foreach ($fields as $field)
<div class="form-group">
@ -49,6 +50,7 @@
</div>
@endforeach
@endif
</div>
</div>