initial commit
This commit is contained in:
28
resources/views/partials/vm-device-fields.blade.php
Normal file
28
resources/views/partials/vm-device-fields.blade.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<div id="devices-container" class="space-y-3">
|
||||
@php $devices = old('devices', $devices ?? []); @endphp
|
||||
@forelse($devices as $i => $device)
|
||||
@include('partials.vm-device-row', ['index' => $i, 'device' => $device, 'deviceTypes' => $deviceTypes])
|
||||
@empty
|
||||
@endforelse
|
||||
</div>
|
||||
<button type="button" id="add-device" class="mt-2 text-sm text-cyan-400 hover:underline">+ Gerät hinzufügen</button>
|
||||
|
||||
<template id="device-row-template">
|
||||
@include('partials.vm-device-row', ['index' => '__INDEX__', 'device' => [], 'deviceTypes' => $deviceTypes])
|
||||
</template>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
document.getElementById('add-device')?.addEventListener('click', () => {
|
||||
const container = document.getElementById('devices-container');
|
||||
const index = container.children.length;
|
||||
const tpl = document.getElementById('device-row-template').innerHTML.replace(/__INDEX__/g, index);
|
||||
container.insertAdjacentHTML('beforeend', tpl);
|
||||
});
|
||||
document.getElementById('devices-container')?.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('remove-device')) {
|
||||
e.target.closest('.device-row')?.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user