TableWidget Actions not working as expected

I'm trying to add actions to a WidgetTable, but the actions don't work as expected. When clicking on the Edit link, it appears to call the Save method as I get a notification in the upper right that it was saved. Where am I going wrong?
protected function getTableActions(): array
{
return [
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
];
}
protected function getTableActions(): array
{
return [
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
];
}
7 Replies
Dan Harrin
Dan Harrin2y ago
you havent passed a ->form()
usmcgator
usmcgatorOP2y ago
what value do I pass in ->form('what_form')? I'm having all kinds of fun trying to get actions to work in TableWidgets. In addtion to the edit/delete links, I'm trying to get an Add Resource button to the widget, but falling short. I think I'm on to something...
EditAction::make()->form(function (Publication $publication) {
$form = Form::make('editPublication', [
'model' => $publication,
]);

$form->schema([
// Define the form fields here
]);

return $form->getSchema();
}),
EditAction::make()->form(function (Publication $publication) {
$form = Form::make('editPublication', [
'model' => $publication,
]);

$form->schema([
// Define the form fields here
]);

return $form->getSchema();
}),
all coming together: DeleteAction::make(), still having an issue adding an "Add Resource" button to the widget, but the actions all work.
Dan Harrin
Dan Harrin2y ago
hmmm just pass the array directly to form() form([TextInput::make()])
usmcgator
usmcgatorOP2y ago
I was trying to get the "Add Resource" button to show up in the table header of the TableWidget, like it does the table when viewing that table using the auto generated resource view page. I tried this, but it didn't make the button show up on the TableWidget:
protected function getTableHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
protected function getTableHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
user error, I got the button to show up now using the above method, I just need to redirect it to the correct create form. got it all working with this:
protected function getTableHeaderActions(): array
{
return [
CreateAction::make()->form(function (Publication $publication) {
$form = Form::make('newPublication', [
'model' => $publication,
]);
$form->schema([
Select::make('type')
->required()
->options([
'book' => 'Book',
'chapter' => 'Chapter',
'journal' => 'Journal',
]),
// ...
]);
return $form->getSchema();
}),
];
}
protected function getTableHeaderActions(): array
{
return [
CreateAction::make()->form(function (Publication $publication) {
$form = Form::make('newPublication', [
'model' => $publication,
]);
$form->schema([
Select::make('type')
->required()
->options([
'book' => 'Book',
'chapter' => 'Chapter',
'journal' => 'Journal',
]),
// ...
]);
return $form->getSchema();
}),
];
}
Dan Harrin
Dan Harrin2y ago
you dont need all of this you just pass an array of fields to the form() this is a long way of just getting a simple array form([Select…])
usmcgator
usmcgatorOP2y ago
Wasn't sure how to flush out your suggestion, is this closer?
protected function getTableHeaderActions(): array
{
return [
CreateAction::make()->form([
Select::make('type')
->required()
->options([
'book' => 'Book',
'chapter' => 'Chapter',
'journal' => 'Journal',
])
]),
];
}
protected function getTableHeaderActions(): array
{
return [
CreateAction::make()->form([
Select::make('type')
->required()
->options([
'book' => 'Book',
'chapter' => 'Chapter',
'journal' => 'Journal',
])
]),
];
}
Dan Harrin
Dan Harrin2y ago
yup thats it
Want results from more Discord servers?
Add your server