Closed Ahmed-Waeel closed 6 months ago
The select-box.blade.php file should be something like that, so we can disable tom-select on desired selects.
select-box.blade.php
@props([ 'title' => null, 'options' => [], 'value' => [], 'id' => uniqid('select-'), 'tom' => true, ]) @php $name = $attributes->get('name') ?? false; $required = str_contains($attributes->get('validation') ?: '', 'required') ?? false; if (! is_array($value)) { $value = is_string($value) ? explode(',', $value) : [$value]; } if (is_array($options) && \Illuminate\Support\Arr::isList($options)) { $options = array_combine($options, $options); } if ($name && str_ends_with($name, '[]') && $attributes->has('multiple') === false) { $attributes = $attributes->merge(['multiple' => true]); } @endphp @if ($title) <x-components::label :title="$title" :for="$id" :required="$required" /> @endif <select id="{{ $id }}" {{ $attributes->merge(['class' => 'form-select', 'init' => $tom ? 'select-box' : null]) }}> @foreach ($options as $key => $label) <option value="{{ $key }}" @selected(in_array($key, $value))>{{ $label }}</option> @endforeach {{ $slot }} </select> @pushOnce('scripts') <script src="{{ asset('/vendor/tom-select/tom-select.complete.min.js') }}"></script> @endpushOnce
Merged
The
select-box.blade.php
file should be something like that, so we can disable tom-select on desired selects.