90 lines
4.5 KiB
PHP
90 lines
4.5 KiB
PHP
@php
|
|
$editing = $row !== null;
|
|
$heading = ($editing ? 'Ubah ' : 'Tambah ').Str::lower($names['singular']);
|
|
@endphp
|
|
|
|
<x-layouts.app :title="$heading">
|
|
<x-ui.page-header
|
|
:title="$heading"
|
|
:description="$names['description'] ?? null"
|
|
:breadcrumbs="[$names['plural'] => route($base.'.index'), $heading => null]"
|
|
/>
|
|
|
|
<form method="POST" action="{{ $action }}" class="stack" novalidate>
|
|
@csrf
|
|
@if ($method !== 'POST') @method($method) @endif
|
|
|
|
@if ($errors->any())
|
|
<x-ui.alert tone="danger" title="Data belum dapat disimpan">Periksa isian yang ditandai lalu coba lagi.</x-ui.alert>
|
|
@endif
|
|
|
|
@foreach ($sections as $title => $fields)
|
|
<x-glass.panel padding="lg">
|
|
<x-form.section :title="$title" :columns="2">
|
|
@foreach ($fields as $field)
|
|
@php
|
|
$type = $field['type'] ?? 'text';
|
|
$span = ($field['span'] ?? null) === 'full' || $type === 'textarea' ? 'col-span-full' : null;
|
|
$attrs = $field['attrs'] ?? [];
|
|
$required = ! ($field['optional'] ?? false) && in_array('required', (array) ($field['rules'] ?? []), true);
|
|
@endphp
|
|
<div @class([$span])>
|
|
@if ($type === 'select')
|
|
<x-form.select
|
|
:name="$field['name']"
|
|
:label="$field['label']"
|
|
:options="$field['options']"
|
|
:value="$field['current']"
|
|
:placeholder="$field['placeholder'] ?? 'Pilih'"
|
|
:hint="$field['hint'] ?? null"
|
|
:optional="$field['optional'] ?? false"
|
|
:required="$required"
|
|
/>
|
|
@elseif ($type === 'textarea')
|
|
<x-form.textarea
|
|
:name="$field['name']"
|
|
:label="$field['label']"
|
|
:value="$field['current']"
|
|
:hint="$field['hint'] ?? null"
|
|
:optional="$field['optional'] ?? false"
|
|
:required="$required"
|
|
:rows="$field['rows'] ?? 4"
|
|
/>
|
|
@elseif ($type === 'checkbox')
|
|
<x-form.checkbox
|
|
:name="$field['name']"
|
|
:label="$field['label']"
|
|
:checked="(bool) old($field['name'], $field['current'] ?? ($field['default'] ?? false))"
|
|
/>
|
|
@else
|
|
<x-form.field
|
|
:name="$field['name']"
|
|
:label="$field['label']"
|
|
:type="$type"
|
|
:value="$field['current']"
|
|
:hint="$field['hint'] ?? null"
|
|
:optional="$field['optional'] ?? false"
|
|
:required="$required"
|
|
:prefix="$field['prefix'] ?? null"
|
|
:suffix="$field['suffix'] ?? null"
|
|
:autocomplete="$type === 'password' ? 'new-password' : 'off'"
|
|
:placeholder="$field['placeholder'] ?? null"
|
|
:min="$attrs['min'] ?? null"
|
|
:max="$attrs['max'] ?? null"
|
|
:step="$attrs['step'] ?? null"
|
|
:maxlength="$attrs['maxlength'] ?? null"
|
|
/>
|
|
@endif
|
|
</div>
|
|
@endforeach
|
|
</x-form.section>
|
|
</x-glass.panel>
|
|
@endforeach
|
|
|
|
<x-form.actions>
|
|
<x-ui.button type="submit" icon="check">{{ $editing ? 'Simpan perubahan' : 'Simpan' }}</x-ui.button>
|
|
<x-ui.button variant="secondary" :href="route($base.'.index')">Batal</x-ui.button>
|
|
</x-form.actions>
|
|
</form>
|
|
</x-layouts.app>
|