62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
|
<x-form.base {{ $attributes }}>
|
||
|
<input type="hidden" id="{{ $name }}_disabled" name="{{ $name }}" value="" disabled>
|
||
|
<select style="width: 80%;" class="form-select @error((! empty($old)) ? $old : $name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @required(isset($required)) @disabled(isset($disabled))>
|
||
|
@if(empty($value) || isset($addnew) || isset($choose))
|
||
|
<option value=""></option>
|
||
|
@isset($addnew)
|
||
|
<option value="new">{{ $addnew ?: 'Add New' }}</option>
|
||
|
@endisset
|
||
|
@endif
|
||
|
|
||
|
@isset($options)
|
||
|
@empty($groupby)
|
||
|
@foreach($options as $option)
|
||
|
@continue(! Arr::get($option,'value'))
|
||
|
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($old ?? $name,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
|
||
|
@endforeach
|
||
|
|
||
|
@else
|
||
|
@foreach($options->groupBy($groupby) as $group)
|
||
|
<optgroup label="{{ $groupby == 'active' ? (Arr::get($group->first(),$groupby) ? 'Active' : 'Not Active') : Arr::get($group->first(),$groupby) }}">
|
||
|
@foreach($group as $option)
|
||
|
@continue(! Arr::get($option,'value'))
|
||
|
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == old($old ?? $name,$value ?? ''))>{{ Arr::get($option,'value') }}</option>
|
||
|
@endforeach
|
||
|
</optgroup>
|
||
|
@endforeach
|
||
|
@endempty
|
||
|
@endisset
|
||
|
</select>
|
||
|
</x-form.base>
|
||
|
|
||
|
@pa(select2)
|
||
|
|
||
|
@section('page-scripts')
|
||
|
<script type="text/javascript">
|
||
|
// Select doesnt support read only so we'll use disable and a new field
|
||
|
function {{$id ?? $name}}_readonly(on) {
|
||
|
if (on) {
|
||
|
$('#{{ $name }}').prop('disabled',true);
|
||
|
$('#{{ $name }}_disabled').prop('disabled',false).val($('#{{ $name }}').val());
|
||
|
|
||
|
} else {
|
||
|
$('#{{ $name }}').prop('disabled',false);
|
||
|
$('#{{ $name }}_disabled').prop('disabled',true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$(document).ready(function() {
|
||
|
$('#{{ $id ?? $name }}').select2({
|
||
|
dropdownAutoWidth: true,
|
||
|
width: 'style',
|
||
|
@isset($addvalues)
|
||
|
tags: true,
|
||
|
@isset($placeholder)
|
||
|
placeholder: '{{ $placeholder ?? '' }}',
|
||
|
@endisset
|
||
|
allowClear: true,
|
||
|
@endisset
|
||
|
});
|
||
|
});
|
||
|
</script>
|
||
|
@append
|