F
Filament2y 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
hxnOP2y 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 Harrin2y ago
what does getUnsetLocales() contain? maybe you need to refresh the relationship in there otherwise it will used the old cached version
hxn
hxnOP2y 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 Harrin2y ago
$options = $this->category_translations()->pluck('locale');
hxn
hxnOP2y ago
Fixed! Thanks a lot
Want results from more Discord servers?
Add your server