{{-- AJAX-paginated select2 skinned as a select2-checkboxes. Props: name : form field name, submitted as name[]. label : control label. endpoint : selectlist endpoint slug (companies, locations, users...). selected : array of pre-selected ids (optional). modelClass : Eloquent model class for pre-rendering option text and tag_color on initial page load. Optional. When omitted pre-selected ids render as id-only text until the user interacts. required : HTML required on the underlying select (optional). companyId : forwarded as data-company-id so the endpoint can scope. excludeId : forwarded as data-exclude-id. onlyTopLevel : forwarded as data-only-top-level (companies hierarchy). help_text : optional help text under the control. countLabel : "{n} selected" by default, overrideable per locale. placeholder : placeholder for the control + dropdown search field. selectAll : enable the "Select all / Clear" row in the dropdown (default true). maxSelectAll : optional per-widget ceiling for ?all=1 (clamped by MAX_UNPAGINATED). labelClass : grid class for the label (default col-md-3). inputClass : grid class for the input column (default col-md-7). --}} @props([ 'name', 'label', 'endpoint', 'selected' => [], 'modelClass' => null, 'required' => false, 'companyId' => null, 'excludeId' => null, 'onlyTopLevel' => false, 'help_text' => null, 'countLabel' => trans('general.checkbox_multiselect_count'), 'placeholder' => '', 'selectAll' => true, 'maxSelectAll' => null, 'labelClass' => 'col-md-3', 'inputClass' => 'col-md-7', ]) @php $selectId = $name.'_select'; $selectedIds = collect($selected ?? [])->filter()->values(); // Pre-fetch the selected models (name + tag_color when available) so // the chip strip renders colored squares and real text on initial // page load, not just the raw id. The tag_color column is optional // per model and read via ?-> so models without one fall to null. $selectedModels = collect(); if ($modelClass && $selectedIds->isNotEmpty()) { $selectedModels = $modelClass::whereIn('id', $selectedIds->all())->get()->keyBy('id'); } @endphp
$errors->has($name)])>
@if ($help_text)
{!! $help_text !!}
@endif