Breaking out field-listing into its own Livewire blade for use elsewhere

This commit is contained in:
Brady Wetherington 2021-03-23 14:24:00 -07:00 committed by Brady Wetherington
parent ea1f1eb972
commit a6ac4f94f1
5 changed files with 58 additions and 38 deletions

View file

@ -36,9 +36,6 @@ class CustomFieldSetDefaultValuesForModel extends Component
public function render()
{
// return 'fart<div>Hi: {{ $this->add_default_values }} yeah?</div>';
if($this->fieldset_id) {
$this->fields = CustomFieldset::find($this->fieldset_id)->fields()->get();
}
return view('livewire.custom-field-set-default-values-for-model');
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\CustomFieldset;
class CustomFieldsForFieldset extends Component
{
public $fieldset_id;
public $fields;
public function render()
{
if($this->fieldset_id) {
$this->fields = CustomFieldset::find($this->fieldset_id)->fields()->get();
}
return view('livewire.custom-fields-for-fieldset');
}
}

View file

@ -17,39 +17,7 @@
<div class="form-group">
<fieldset>
<legend class="col-md-3 control-label">Default Values</legend>
<div class="col-sm-8 col-xl-7">
@empty($fields) {{-- There was an error? --}}
<p>
There was a problem retrieving the fields for this fieldset.
</p>
@else
{{-- NOTE: This stuff could work well also for the 'view this asset and do its custom fields' thing --}}
@foreach($fields as $field)
<div class="row">
<div class="col-sm-12 col-lg-6">
<label class="control-label" for="default-value{{ $field->id }}">{{ $field->name }}</label>
</div>
<div class="col-sm-12 col-lg-6">
@if($field->element == "text")
<input b-if="field.type == 'text'" class="form-control m-b-xs" type="text" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'">
@elseif($field->element == "textarea")
<textarea x-if="field.type == 'textarea'" class="form-control" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'"></textarea><br>
@elseif($field->element == "listbox")
<select Z-if="field.element == 'listbox'" class="form-control m-b-xs" :name="'default_values[' + field.id + ']'">
<option value=""></option>
@foreach($field->field_values as $field_value)
<option Q-for="field_value in field.field_values_array" :value="field_value" :selected="getValue(field) == field_value">{{ $field_value }}</option>
@endforeach
</select>
@else
Unknonown field element: {{ $field->element }}
@endif
</div>
</div>
@endforeach
@endif
</div>
@livewire('custom-fields-for-fieldset',['fieldset_id' => $fieldset_id])
</fieldset>
</div>
</div>

View file

@ -0,0 +1,34 @@
<div class="col-sm-8 col-xl-7">
@empty($fields) {{-- There was an error? --}}
<p>
There was a problem retrieving the fields for this fieldset.
</p>
@else
{{-- NOTE: This stuff could work well also for the 'view this asset and do its custom fields' thing --}}
{{-- I don't know if we break *here* or if we break per field element? --}}
@foreach($fields as $field)
<div class="row">
<div class="col-sm-12 col-lg-6">
<label class="control-label" for="default-value{{ $field->id }}">{{ $field->name }}</label>
</div>
<div class="col-sm-12 col-lg-6">
@if($field->element == "text")
<input b-if="field.type == 'text'" class="form-control m-b-xs" type="text" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'">
@elseif($field->element == "textarea")
<textarea x-if="field.type == 'textarea'" class="form-control" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'"></textarea><br>
@elseif($field->element == "listbox")
<select Z-if="field.element == 'listbox'" class="form-control m-b-xs" :name="'default_values[' + field.id + ']'">
<option value=""></option>
@foreach($field->field_values as $field_value)
<option Q-for="field_value in field.field_values_array" :value="field_value" :selected="getValue(field) == field_value">{{ $field_value }}</option>
@endforeach
</select>
@else
Unknonown field element: {{ $field->element }}
@endif
</div>
</div>
@endforeach
@endif
</div>

View file

@ -82,10 +82,10 @@
@stop
@section('moar_scripts')
{{-- @section('moar_scripts')
<script nonce="{{ csrf_token() }}">
new Vue({
el: '#app'
});
</script>
@endsection
@endsection --}}