57 lines
2.3 KiB
PHP
57 lines
2.3 KiB
PHP
{{-- blade-formatter-disable --}}
|
|
{{--
|
|
VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT
|
|
|
|
$id || The id of the select tag. || string || REQUIRED ||
|
|
$name || The name of the select tag. || string || REQUIRED ||
|
|
$options || List of options. Can be enum-like. || array || REQUIRED ||
|
|
$helper || The helper of the input. || string || REQUIRED ||
|
|
$label || The label displayed. || string || OPTIONNAL || null
|
|
$required || Is the field required ? || boolean || OPTIONNAL || false
|
|
$placeholder || Placeholder label. || string || OPTIONNAL || __('forms.select.placeholder')
|
|
$model || Model for binding value. || Model|null || OPTIONNAL || null
|
|
$disabled || Disable the field. || boolean || OPTIONNAL || false
|
|
$readonly || Make the select readonly. || boolean (HTML) || OPTIONNAL || false
|
|
--}}
|
|
|
|
@php
|
|
$selectedValue = old($name, $model->{$name}->value ?? null);
|
|
@endphp
|
|
|
|
@if (!empty($label))
|
|
<label class="col-form-label" for="{{ $id }}">
|
|
<b>{{ $label }} {{ $required ?? false ? '*' : '' }}</b>
|
|
</label>
|
|
@endif
|
|
|
|
<select
|
|
name="{{ $name }}"
|
|
id="{{ $id }}"
|
|
class="form-select @if ($errors->has($name)) is-invalid @endif"
|
|
aria-describedby="{{ $id }}Help"
|
|
@disabled(!empty($disabled))
|
|
@readonly(!empty($readonly))
|
|
@required(!empty($required))
|
|
>
|
|
@if (!empty($placeholder))
|
|
<option value="">{{ $placeholder }}</option>
|
|
@endif
|
|
|
|
@foreach($options as $key => $item)
|
|
@php
|
|
$optionValue = is_object($item) && isset($item->value) ? $item->value : $key;
|
|
$optionLabel = is_object($item) && isset($item->label) ? $item->label : (is_scalar($item) ? $item : $key);
|
|
@endphp
|
|
|
|
<option value="{{ $optionValue }}"
|
|
@selected((string) $selectedValue === (string) $optionValue)>
|
|
{{ $optionLabel }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
|
|
@include('modules.input-error', [
|
|
'inputName' => $name,
|
|
'helperId' => "{$id}Help",
|
|
'helper' => $helper,
|
|
])
|