FilamentF
Filament3y ago
hpsi

Select::make multiple, searchable

Hi simple problem:
Custom form (code below), if select, is not multiple-searchable statePath saves changes after picking one correctly (screen1), but when I added ->searchable()->multiple() (screen 2,3) this select after pick data did not store data in statePath

example of code
namespace App\Filament\Resources\CourseResource\Pages;

use App\Filament\Resources\CourseResource;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Resources\Pages\Page;
use Filament\Forms\Form;
use Filament\Support\Exceptions\Halt;


class CourseManage extends Page implements HasForms
{
    use InteractsWithForms;
    protected static string $resource = CourseResource::class;
    protected static bool $shouldRegisterNavigation = false;

    protected static string $view = 'filament.resources.course-resource.pages.course-manage';

    public array $companyData = [];

    public function mount(): void
    {
      #  $this->fillForm();
    }

    protected function getForms(): array
    {
        return [
            'companyForm',
        ];
    }

    public function companyForm(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('company')
                    ->options([0 => 'one', 1 => 'two', 2 => 'three', 3 => 'other'])
                    ->label('')
                    ->searchable()
                    ->multiple()
                    ->required()
            ])
            ->statePath('companyData');
    }

    public function getAddAllEmployeesFromCompanyActions(): array {
         return [
            Action::make('addAllEmployeeFromCompanyAction')
                ->label('add')
                ->submit('addCompanyEmployeesForm')
        ];
    }

    public function addCompanyEmployeesForm() {
        try {
            $data = $this->companyForm->getState();
            dd($data);

        } catch (Halt $exception) {
            return;
        }
    }
}
image.png
image.png
image.png
Was this page helpful?