Use Action inside a custom field

Hello, i have a error in my custom field, because i have 2 form submit buttons. Field:
class ObjectPaymentFunction extends Field
{
protected string $view = 'forms.components.custom-field';
}
class ObjectPaymentFunction extends Field
{
protected string $view = 'forms.components.custom-field';
}
forms.components.custom-field.blade.php:
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div>
{{ $this->billCreatedAction() }}
<x-filament-actions::modals />
</div>
</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div>
{{ $this->billCreatedAction() }}
<x-filament-actions::modals />
</div>
</x-dynamic-component>
EditCustomer:
class EditCustomer extends EditRecord
{
public function billCreatedAction(): Action
{
return Action::make('billCreated')
->label('Close')
->requiresConfirmation()
->action(function () {
dd('billAction');
});
}
}
class EditCustomer extends EditRecord
{
public function billCreatedAction(): Action
{
return Action::make('billCreated')
->label('Close')
->requiresConfirmation()
->action(function () {
dd('billAction');
});
}
}
The error: The action is shown correctly, also the modal is asking for confirmation. But on confimation the save Button in the backgound on the create page is triggered. And the record is saved. But the modal is still open. Is there a way to separate the "confimation form" on the edit page?
37 Replies
awcodes
awcodes10mo ago
{{ $this->billCreatedAction }} No () on the action.
BOT_Larry
BOT_LarryOP10mo ago
Thanks i changed it, but it made no difference with my problem
BOT_Larry
BOT_LarryOP10mo ago
No description
BOT_Larry
BOT_LarryOP10mo ago
Here a screenshot from this error. I hit submit on the modal ("Bestätigen") You can see the submit button in the background spinning, but the modal is not submiting.
gemini.dev
gemini.dev8mo ago
Any updates on this?
Dan Harrin
Dan Harrin8mo ago
technically you should use form component actions for this use case, not normal livewire actions i dont see the error screenshot either
gemini.dev
gemini.dev8mo ago
Hi @Dan Harrin, it does not appear to be an option version 2 of filament.
Dan Harrin
Dan Harrin8mo ago
it is, just not documented
gemini.dev
gemini.dev8mo ago
One second, let me have a look.
Dan Harrin
Dan Harrin8mo ago
i think the v3 docs are mostly accurate for v2
gemini.dev
gemini.dev8mo ago
Can it be added here (see bottom)?: public static function form(Form $form): Form { return $form ->schema([ Toggle::make('generate_pdf_files')->label('Generate PDF file(s)')->reactive()->default(true), Forms\Components\Select::make('filing_type') ->label('Filing Type') ->options([ 'Monthly' => 'Monthly', 'Quarterly' => 'Quarterly', ]) ->default('Quarterly') ->helperText('Select monthly to round by month instead of quarter') ->required(condition: fn(Closure $get): bool => $get('generate_pdf_files')) ->hidden(function (callable $get) { return !$get('generate_pdf_files'); }), Forms\Components\Select::make('country_code') ->label('Country') ->options(array("" => "Select Country") + app(GeneralSettings::class)->report_countries) ->default('') ->disablePlaceholderSelection() ->required(condition: fn(Closure $get): bool => $get('generate_pdf_files')) ->hidden(function (callable $get) { return !$get('generate_pdf_files'); }), FileUpload::make('filename') ->acceptedFileTypes(['text/csv', 'text/plain']) ->preserveFilenames() ->multiple() ->visibility('private') ->label('CSV/TXT File') ->required() // <------------------------------------------------ Can it be added here? ])->columns(1); }
Dan Harrin
Dan Harrin8mo ago
uhhh what are you trying to do where will the button be in the file upload
gemini.dev
gemini.dev8mo ago
This is the idea: 1. User fills form. 2. Once the file is available, have a custom button at the bottom to run an algorithm against the data and download the result into .csv 3. Once create is clicked, it will do what it does now. It runs an alternative algorithm and generates a PDF. That extra button is there to simply to generate an optional downloadable report.
gemini.dev
gemini.dev8mo ago
No description
gemini.dev
gemini.dev8mo ago
Alternative solution is probably do whatever it does here.. but after the creation, prompt a popup (Would you like to download a report)...
Dan Harrin
Dan Harrin8mo ago
add a View::make() component in the view file, <x-filament::button wire:click="download">Download</x-filament::button>
public function download()
{
dd($this->data);
}
public function download()
{
dd($this->data);
}
that is the simplest way
gemini.dev
gemini.dev8mo ago
Will give that a try now 🙂 Ah did not work: Property [$data] not found on component: [app.filament.resources.data-resource.pages.manage-data] Let me provide you some code...
gemini.dev
gemini.dev8mo ago
DataResource file
gemini.dev
gemini.dev8mo ago
ManageRecords, where the download is: <?php namespace App\Filament\Resources\DataResource\Pages; use App\Filament\Resources\DataResource; use App\Helpers\Helpers; use Filament\Pages\Actions\CreateAction; use Filament\Resources\Pages\ManageRecords; use Illuminate\Database\Eloquent\Collection; use Filament\Forms\Components\Actions\Action; class ManageData extends ManageRecords { protected static string $resource = DataResource::class; protected function getActions(): array { $records = new Collection(); return [ CreateAction::make() ->disableCreateAnother() ->using(function (array $data) use (&$records) { foreach ($data['filename'] as $filename) { $records[] = static::getModel()::create(['filename' => $filename]); } }) ->after(function (array $data) use ($records): ?\Symfony\Component\HttpFoundation\StreamedResponse { if (isset ($data['generate_pdf_files']) && $data['generate_pdf_files'] === true) { $response = Helpers::generatePDF($data, $records); return $response; } return null; }) ]; } public function download() { // get data here dd($this->data); } protected function getTableRecordsPerPageSelectOptions(): array { return [50, 100]; } } FormAction button: <?php namespace App\Forms\Components; use Filament\Forms\Components\Field; class FormActionButton extends Field { protected string $view = 'forms.components.form-action-button'; } And here is the form-action-button.blade.php: <x-dynamic-component :component="$getFieldWrapperView()" :id="$getId()" :label="$getLabel()" :label-sr-only="$isLabelHidden()" :helper-text="$getHelperText()" :hint="$getHint()" :hint-action="$getHintAction()" :hint-color="$getHintColor()" :hint-icon="$getHintIcon()" :required="$isRequired()" :state-path="$getStatePath()"> <div x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"> <x-filament::button wire:click="download">Download ESL</x-filament::button> </div> </x-dynamic-component> I tried adding the download function into: ManageRecords page, but it does not find the component of $data oh this appears to work: public function download() { // get data here dd($this->mountedActionData); }
Dan Harrin
Dan Harrin8mo ago
if you upgrade to v3 its easier
gemini.dev
gemini.dev8mo ago
Thanks Dan 🙂 Yes have it planned in works to upgrade to v3, I'll give that a try tomorrow. Definetly needing to upgrade now than later
Dan Harrin
Dan Harrin8mo ago
btw, this doesnt need to be a "field" just a "layout component" you dont need anything in the view apart from the button
gemini.dev
gemini.dev8mo ago
How do you mean?
Dan Harrin
Dan Harrin8mo ago
your view is overcomplicated
gemini.dev
gemini.dev8mo ago
Ah that was the default one I just added the button lol
Dan Harrin
Dan Harrin8mo ago
you dont even need the extra class
Dan Harrin
Dan Harrin8mo ago
just use this and create a file with ONLY the button
gemini.dev
gemini.dev8mo ago
Everything else was made by filament when creating the form field using CMD
Dan Harrin
Dan Harrin8mo ago
no other divs or the dynamic component its not a field. fields have actual state (data) associated this is just a button
gemini.dev
gemini.dev8mo ago
right I see
Dan Harrin
Dan Harrin8mo ago
a field would be an input or something that can store data
gemini.dev
gemini.dev8mo ago
Gotcha, yeah spent 5 hours faffing about haha
Dan Harrin
Dan Harrin8mo ago
and replying to every remotely related forum thread instead of just creating a new one 😉
gemini.dev
gemini.dev8mo ago
Yeah I did both 🤣
Want results from more Discord servers?
Add your server