I'm using FilamentPHP and I come to you because I lose the placeholder of my select when I reset it. A video is much more telling:
I'm using the layout (https://filamentphp.com/tricks/render-html-in-select-options) and haven't had any issues so far. It looks like there is a reload conflict between my selects.
A snippet of my code:
Forms\Components\Select::make('extendedProps.type_task_id')
->label('Type de tâche')
//->required()
->allowHtml()
->searchable()
// Chargement du formulaire au chargement
->options(function(Closure $get) {
$types = collect([]);
if(!empty($get('extendedProps.team_id'))) {
$types = TypeTask::where('team_id', $get('extendedProps.team_id'))->get();
}
return $types->mapWithKeys(function ($type) {
return [$type->getKey() => static::getSelectIcon($type)];
})->toArray();
})
// Chargement du formulaire à la recherche
->getSearchResultsUsing(function (Closure $get, string $search) {
$types = collect([]);
if(!empty($get('extendedProps.team_id'))) {
$types = TypeTask::where('team_id', $get('extendedProps.team_id'))
->where('name', 'like', "%{$search}%")
->limit(50)
->get();
}
return $types->mapWithKeys(function ($type) {
return [$type->getKey() => static::getSelectIcon($type)];
})->toArray();
})
->reactive()
->preload()
->columnSpan(12)
// Modification après sélection
->afterStateUpdated(function (Closure $set, Closure $get, $state) {
if ($get('extendedProps.product_id') !== null) {
$set('extendedProps.product_id', null);
}
if ($get('extendedProps.device_id') !== null) {
$set('extendedProps.device_id', null);
}
})
->extraAttributes(['class' => 'coucou-test'])
->placeholder('Libre')
->hidden(function(Closure $get) {
$types = collect([]);
if(!empty($get('extendedProps.team_id'))) {
$types = TypeTask::where('team_id', $get('extendedProps.team_id'))->get();
if(count($types) == 0) {
return true;
}
}
else {
return true;
}
return false;
}),
Forms\Components\Select::make('extendedProps.product_id')
->label('Produit')
->required()
->allowHtml()
->searchable()
// Chargement du formulaire au chargement
->options(function(Closure $get) {
$products = collect([]);
if(in_array($get('extendedProps.type_task_id'), [1, 2])) { // Brassage + Conditionnement
$products = Product::where('is_crafted', 1)->get();
}
else { // Ou le reste
$products = Product::where('is_crafted', 0)->get();
}
return $products->mapWithKeys(function ($product) {
return [$product->getKey() => static::getCleanOptionStringProduct($product)];
})->toArray();
})
// Chargement du formulaire à la recherche
->getSearchResultsUsing(function (Closure $get, string $search) {
$products = collect([]);
if(in_array($get('extendedProps.type_task_id'), [1, 2])) { // Brassage + Conditionnement
$products = Product::where('is_crafted', 1);
}
else { // Ou le reste
$products = Product::where('is_crafted', 0);
}
$products = $products->where('name', 'like', "%{$search}%")
->limit(50)
->get();
return $products->mapWithKeys(function ($product) {
return [$product->getKey() => static::getCleanOptionStringProduct($product)];
})->toArray();
})
->reactive()
->preload()
->columnSpan(6)
->hidden(function(Closure $get) {
if($get('extendedProps.type_task_id') != null) {
return false;
}
return true;
})
->placeholder('Libre'),
Apart from this layout defect, everything works as I wish. If you have any idea where is my problem? Any history of reset conflict? Got a choice.js issue? A problem loading HTML in my select like this is reset?
Good for you, Thank's.