F
Filament15mo ago
hxn

Select options not updated when using "create & create another" button

In a RelationManager i'm using
Forms\Components\Select::make('locale')
->required()
->options(fn (RelationManager $livewire) => $livewire->ownerRecord->getUnsetLocales())
Forms\Components\Select::make('locale')
->required()
->options(fn (RelationManager $livewire) => $livewire->ownerRecord->getUnsetLocales())
When using "Create" button all good but when i'm using the "create & create another" button my options isnt updated
5 Replies
hxn
hxn15mo ago
For now i've just disabled CreateAnother but if someone have another solution to achieve what i want it will be great (getUnsetLocales() simply return an array of non used locales)
->headerActions([
Tables\Actions\CreateAction::make()
->disableCreateAnother(),
Tables\Actions\AssociateAction::make(),
])
->headerActions([
Tables\Actions\CreateAction::make()
->disableCreateAnother(),
Tables\Actions\AssociateAction::make(),
])
Dan Harrin
Dan Harrin15mo ago
what does getUnsetLocales() contain? maybe you need to refresh the relationship in there otherwise it will used the old cached version
hxn
hxn15mo ago
public function getUnsetLocales() {
$translations = collect(['en' => 'en', 'pt' => 'pt']);
$options = $this->category_translations->map(fn($item) => $item->locale);

return $translations->diff($options)->toArray();
}
public function getUnsetLocales() {
$translations = collect(['en' => 'en', 'pt' => 'pt']);
$options = $this->category_translations->map(fn($item) => $item->locale);

return $translations->diff($options)->toArray();
}
any idea how to trigger a refresh when user press the "create & create another"? I have similar(minor) problem on headerActions:
->headerActions([
Tables\Actions\CreateAction::make()
->disabled(fn (RelationManager $livewire) => !$livewire->ownerRecord->getUnsetLocales())
->disableCreateAnother(),
])
->headerActions([
Tables\Actions\CreateAction::make()
->disabled(fn (RelationManager $livewire) => !$livewire->ownerRecord->getUnsetLocales())
->disableCreateAnother(),
])
If i create the last possible translation and save it. The button to create a new record in the relation is still in primary color (but its a minor issue cause when clicking on it it does nothing). Only after refreshing the page the color is darker as expected
Dan Harrin
Dan Harrin15mo ago
$options = $this->category_translations()->pluck('locale');
hxn
hxn15mo ago
Fixed! Thanks a lot