Update Koperasi
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
@props([
|
||||
'model', 'name', 'label', 'options' => [], 'multiple' => false,
|
||||
'type' => 'text', 'placeholder' => null, 'exclusiveValue' => null, 'help' => null,
|
||||
'policy' => null, 'min' => 0, 'max' => null, 'unit' => null,
|
||||
])
|
||||
|
||||
@php
|
||||
$value = old($name, $model->{$name});
|
||||
$id = 'koperasi-' . str_replace('_', '-', $name);
|
||||
$policy ??= app(\App\Services\Koperasi\OperasionalKoperasiService::class);
|
||||
$data = array_replace($model->getAttributes(), session()->getOldInput());
|
||||
$visible = $policy->active($name, $data, $policy->context($model));
|
||||
$required = $visible && in_array($name, $policy->requiredFields(), true);
|
||||
$error = $errors->first($name) ?: $errors->first($name . '.*');
|
||||
@endphp
|
||||
|
||||
<div {{ $attributes->class(['mb-4', 'form-control-validation', 'd-none' => !$visible]) }}
|
||||
data-koperasi-survey-field="{{ $name }}" data-koperasi-conditions="{{ json_encode($policy->dependencies()[$name] ?? []) }}"
|
||||
@if($exclusiveValue) data-koperasi-exclusive="{{ $exclusiveValue }}" @endif>
|
||||
@if($multiple)
|
||||
<fieldset>
|
||||
<legend class="form-label mb-3">{{ $label }} <span class="text-danger {{ $required ? '' : 'd-none' }}" data-koperasi-required-indicator>*</span></legend>
|
||||
<div class="row g-2">
|
||||
@foreach($options as $option)
|
||||
<div class="col-md-6">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input {{ $error ? 'is-invalid' : '' }}" id="{{ $id }}-{{ $loop->index }}" name="{{ $name }}[]" value="{{ $option->value }}"
|
||||
@checked(\App\Services\Koperasi\PengurusKoperasiService::hasSelection($value, $option->value)) @disabled(!$visible)>
|
||||
<label class="form-check-label" for="{{ $id }}-{{ $loop->index }}">{{ $option->label() }}</label>
|
||||
@if(method_exists($option, 'description') && $option->description())<div class="form-text mt-0">{{ $option->description() }}</div>@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</fieldset>
|
||||
@else
|
||||
<label class="form-label" for="{{ $id }}">{{ $label }} <span class="text-danger {{ $required ? '' : 'd-none' }}" data-koperasi-required-indicator>*</span></label>
|
||||
@if($options)
|
||||
<select class="form-select {{ $error ? 'is-invalid' : '' }}" id="{{ $id }}" name="{{ $name }}" @disabled(!$visible) @required($required)>
|
||||
<option value="">Pilih {{ $label }}</option>
|
||||
@foreach($options as $option)
|
||||
<option value="{{ $option->value }}" @selected(\App\Services\Koperasi\PengurusKoperasiService::hasSelection($value, $option->value))>{{ $option->label() }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@elseif($type === 'textarea')
|
||||
<textarea class="form-control {{ $error ? 'is-invalid' : '' }}" id="{{ $id }}" name="{{ $name }}" rows="3" placeholder="{{ $placeholder }}" @disabled(!$visible) @required($required)>{{ $value }}</textarea>
|
||||
@else
|
||||
@if($unit || $type === 'rupiah')<div class="input-group">@endif
|
||||
@if($type === 'rupiah')
|
||||
<span class="input-group-text">Rp</span>
|
||||
<x-koperasi-rupiah :name="$name" :value="$value" :id="$id" :disabled="!$visible" :required="$required" :show-error="false" placeholder="{{ $placeholder }}" />
|
||||
@else
|
||||
<input type="{{ $type }}" class="form-control {{ $error ? 'is-invalid' : '' }}" id="{{ $id }}" name="{{ $name }}" value="{{ $value }}" placeholder="{{ $placeholder }}" @if($type === 'number') min="{{ $min }}" @if($max !== null) max="{{ $max }}" @endif @endif @disabled(!$visible) @required($required)>
|
||||
@endif
|
||||
@if($unit)<span class="input-group-text">{{ $unit }}</span>@endif
|
||||
@if($unit || $type === 'rupiah')</div>@endif
|
||||
@endif
|
||||
@endif
|
||||
@if($help)<div class="form-text">{{ $help }}</div>@endif
|
||||
@if($error)<div class="invalid-feedback d-block">{{ $error }}</div>@endif
|
||||
</div>
|
||||
Reference in New Issue
Block a user