{{-- select2 from array --}} @php $field['allows_null'] = $field['allows_null'] ?? $crud->model::isColumnNullable($field['name']); $field['value'] = old_empty_or_null($field['name'], '') ?? $field['value'] ?? $field['default'] ?? ''; $field['multiple'] = $field['multiple'] ?? $field['allows_multiple'] ?? false; $field['placeholder'] = $field['placeholder'] ?? ($field['multiple'] ? trans('backpack::crud.select_entries') : trans('backpack::crud.select_entry')); $field['closeOnSelect'] = $field['closeOnSelect'] ?? !$field['multiple']; $field['sortable'] = $field['multiple'] ? ($field['sortable'] ?? false) : false; $field['tagging'] = $field['tagging'] ?? false; // Add any values from $field['value'] that don't exist in $field['options'] as options $options = $field['options'] ?? []; if ($field['sortable']) { $optionsFromValue = []; foreach (\Illuminate\Support\Arr::wrap($field['value']) as $key) { if (!is_array($key) && $key !== '') { $optionsFromValue[$key] = $options[$key] ?? $key; } } $options = $optionsFromValue + $options; } else { foreach (\Illuminate\Support\Arr::wrap($field['value']) as $key) { if (!isset($options[$key]) && !is_array($key) && $key !== '') { $options[$key] = $key; } } } @endphp @include('crud::fields.inc.wrapper_start') {{-- To make sure a value gets submitted even if the "select multiple" is empty, we need a hidden input --}} @if($field['multiple'])@endif {{-- HINT --}} @if (isset($field['hint']))
{!! $field['hint'] !!}
@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} {{-- Extra CSS and JS for this particular field --}} {{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}} {{-- FIELD CSS - will be loaded in the after_styles section --}} @push('crud_fields_styles') {{-- include select2 css --}} @basset('https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css') @basset('https://cdn.jsdelivr.net/npm/select2-bootstrap-theme@0.1.0-beta.10/dist/select2-bootstrap.min.css') @endpush {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') {{-- include select2 js --}} @basset('https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js') @basset('https://cdn.jsdelivr.net/npm/jquery-ui@1.13.2/dist/jquery-ui.min.js') @if (app()->getLocale() !== 'en') @basset('https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/i18n/' . str_replace('_', '-', app()->getLocale()) . '.js') @endif @bassetBlock('backpack/pro/fields/select2-from-array-field.js') @endBassetBlock @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}