Form Actions\Action everything null

Brain fart? Why is everything returning null or []. This is within a form schema()
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
})
->button(),
]),
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
})
->button(),
]),
18 Replies
Kenneth Sese
Kenneth Sese16mo ago
I know you're on standalone, but in the edit page of a resource, $record is returning the record I'm editing and $get is returning the other field I'm getting. Not sure why the others aren't working...digging through resolveDefaultClosureDependencyForEvaluationByName $form doesn't appear to be an acceptable parameter so it'll just return an empty array. $data should return $this->getFormData()...not sure why it's not.
awcodes
awcodes16mo ago
Well if there’s no form defined on the action then the action will not have form data. Actions don’t natively inherit based on where they are registered and cached.
Mark Chaney
Mark ChaneyOP16mo ago
@awcodes even when it’s a form action within the actual form? The form is in a modal and launched from an EditRecord on a table
awcodes
awcodes16mo ago
You have to mount the action with the data. $data will always be null if you don’t pass the data to it.
Mark Chaney
Mark ChaneyOP16mo ago
advice for the best way to fetch such info when its an action in an form in a modal launched by editrecord on a table? 😛 not having access to $get stinks. trying to do basically a note input section within the form that can easily be submitted by that internal form action without affecting the rest of the form
Kenneth Sese
Kenneth Sese16mo ago
Maybe registering the action in the edit record action using registerActions()? (I think that’s the method name). That might give you access to the form???
Mark Chaney
Mark ChaneyOP16mo ago
i think thats only available for a view component or infolist
awcodes
awcodes16mo ago
You don’t need access to the form only the data on the livewire component.
Kenneth Sese
Kenneth Sese16mo ago
Sorry…it’s registerModalActions(). But that might not work anyway. I might not be totally wrapping my head around what you are trying to do, and this might not be the best way, but I was able to use registerModalActions() to register another action and in that first action, and then by dd($livewire) inside action() I had access to the the form data in the initial modal. Again, there might be an easiser way
Mark Chaney
Mark ChaneyOP16mo ago
That gave you access to changes within the form like you would get with $get? I think it would only get it initial data. I will give it a try though. @archilex ok, so i did
EditAction::make('view')
->label('View')
->icon('heroicon-o-eye')
->color('primary')
->modalHeading(false)
->form(PropertyInquiry::getForm())
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
])
->slideOver(),
EditAction::make('view')
->label('View')
->icon('heroicon-o-eye')
->color('primary')
->modalHeading(false)
->form(PropertyInquiry::getForm())
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
])
->slideOver(),
but zero clue on how to now access that action within my PropertyInquiry::getForm() form schema or is it expected to use modalContant() and setup a form method and load the form and action within that view as if it was standalone livewire componet?
Kenneth Sese
Kenneth Sese16mo ago
Ah yes...sorry, I thought your form modal was a standalone livewire component where you could then render the action...I mean you could still do that, but there has to be a better way...hmmmm Wait...can you not affix the action to a field?? Yes...if you can live with the button living at the end of an input field then this works:
Forms\Components\TextInput::make('name')
->suffixAction(
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$name = $get('name');
ray($name)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
),
Forms\Components\TextInput::make('name')
->suffixAction(
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$name = $get('name');
ray($name)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
),
Mark Chaney
Mark ChaneyOP16mo ago
I think i solved it actually a bit more convoluted than it should be though
Kenneth Sese
Kenneth Sese16mo ago
I guess you could even make a custom input that is really just an empty input so you can attach your action to it. A custom input seems like a good way to go actually... As long as it uses the suffixAction method it should work.
Mark Chaney
Mark ChaneyOP16mo ago
EditAction::make('view')
->label('View')
->icon('heroicon-o-eye')
->color('primary')
->modalHeading(false)
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $form) {
ray($record)->label('record note');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
])
->form(fn ($record, $action) => PropertyInquiry::getForm($record, $action))
->slideOver(),
EditAction::make('view')
->label('View')
->icon('heroicon-o-eye')
->color('primary')
->modalHeading(false)
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $form) {
ray($record)->label('record note');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
])
->form(fn ($record, $action) => PropertyInquiry::getForm($record, $action))
->slideOver(),
and then
public static function getForm($record = null, $action = null): array
{
return [.......
View::make('livewire.property-inquiry-notes')
->viewData(['record' => $record, 'action' => $action])
->label('Notes')
->columnSpanFull(),
]),
];
}
public static function getForm($record = null, $action = null): array
{
return [.......
View::make('livewire.property-inquiry-notes')
->viewData(['record' => $record, 'action' => $action])
->label('Notes')
->columnSpanFull(),
]),
];
}
and then
<div>
{{ $action->getModalAction('add_note') }}
</div>
<div>
{{ $action->getModalAction('add_note') }}
</div>
in the blade lol
Kenneth Sese
Kenneth Sese16mo ago
Hey if it works!! Went ahead and did this:
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\TextInput;

class ActionInput extends TextInput
{
/**
* @var view-string
*/
protected string $view = 'components.action-input';
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\TextInput;

class ActionInput extends TextInput
{
/**
* @var view-string
*/
protected string $view = 'components.action-input';
}
@php
$suffixActions = $getSuffixActions();
@endphp

<div>
@foreach ($suffixActions as $suffixAction)
{{ $suffixAction }}
@endforeach
</div>
@php
$suffixActions = $getSuffixActions();
@endphp

<div>
@foreach ($suffixActions as $suffixAction)
{{ $suffixAction }}
@endforeach
</div>
And then you can resuse this wherever you want
ActionInput::make('action')
->suffixAction(
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
),
ActionInput::make('action')
->suffixAction(
Action::make('add_note')
->label('Add Note')
->action(function ($data, $record, $get, $form, $state) {
ray($data)->label('data');
ray($record)->label('record note');
$note = $get('note');
ray($note)->label('note');
ray($form)->label('form');
ray($state)->label('state');
// log_name, description, subject_id, subject_type, causer_id, causer_type, tenant_id
//log_this('Inquiry Note', $note, $record->id, 'App\Models\PropertyInquiry', auth()->user()->id, 'App\Models\User', $record->tenant_id);
})
->button()
->size('sm')
->color('primary'),
),
That might not entirely work though...only getting the $current record, not updated fields...but you've got a working solution so I wont dig into this anymore.
Mark Chaney
Mark ChaneyOP16mo ago
so i ended up having to do the following on the action
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($livewire, $record) {
$note = $livewire->mountedTableActionsData[0]['note'];
if ($note) {
Activity::create([
'log_name' => 'Inquiry Note',
'description' => $note,
'subject_id' => $record->id,
'subject_type' => 'App\Models\PropertyInquiry',
'causer_id' => auth()->user()->id,
'causer_type' => 'App\Models\User',
'tenant_id' => $record->tenant_id,
]);
}
})
->button()
->size('sm')
->color('primary'),
])
->registerModalActions([
Action::make('add_note')
->label('Add Note')
->action(function ($livewire, $record) {
$note = $livewire->mountedTableActionsData[0]['note'];
if ($note) {
Activity::create([
'log_name' => 'Inquiry Note',
'description' => $note,
'subject_id' => $record->id,
'subject_type' => 'App\Models\PropertyInquiry',
'causer_id' => auth()->user()->id,
'causer_type' => 'App\Models\User',
'tenant_id' => $record->tenant_id,
]);
}
})
->button()
->size('sm')
->color('primary'),
])
to get the current note being inputed in the form. Its a big cluster though and i dont like it and now i realized i cant easily have access to $set to null out that note input form after sending. Its not super hard to follow, but it shouldnt be this messy im actually undoing it all. its just not maintaintable and easy to test. too many things for such a basic action. im simply just going to save the note on main save an Action in a form should have full access to the form data
Kenneth Sese
Kenneth Sese16mo ago
Take a look at my idea again...what I shared isn't working because I threw away all of the original view, but when you just use the suffixAction on a normal TextInput, you get access to both $get and $set. I just tried and it's working as expected. So I bet if you dig through the original text-input.blade.php file you'll be able to find the pieces that I removed that make this work with a custom Input. It's probably a $getState or something like that that needs to stay in there. Again, this might not be what you are trying to do, but as a proof of concept, here's a demo video:
Kenneth Sese
Kenneth Sese16mo ago
Want results from more Discord servers?
Add your server