Troubleshooting Default Value Display in Custom Resource Page
I have built a custom resource page, and inside it, I have a 'mount' function. However, the default value doesn't appear when I click on the 'Send Email' button and I want to be able to edit the page after receiving the default value and save the edited data in the database. How can I do this?
2 Replies
For forms you can set a default value like this:
TextInput::make('name')
->default('John')
See docs for more info: https://filamentphp.com/docs/3.x/forms/fields/getting-started#setting-a-default-value
Or do you mean something else? The edit form automaticly appears after you succesfully created a new record. (except if you also created a view)
My workflow is like this:
I have created a record, and after that, an email is triggered to the respective manager with the same data I have created. The data is initially rendered using the mount() method, and the respective manager can edit the field data and save that data.
It worked perfectly in Filament v2, but now I am facing an issue in Filament v3. In Filament v3, the error I'm facing is that my form data is not showing in the UI. However, when I use the dd method to inspect the response, I can see that all the data is present.
The error I encounter in the UI is as follows:
"Unable to find component: [app.filament.resources.appraisal-response-resource.pages.appraisal-response-request]"
and here is the sample code:
class ResponseRequest extends EditRecord
{
protected static string $resource = ResponseResource::class;
protected static string $layout = 'components.response-request.layouts.index';
protected function authorizeAccess(): void
{
}
public function mount(int | string $record = null): void
{
try { $data = JWT::decode(app('request')->input('token'), ['header' => true]); } catch (\Throwable $th) { abort(403); } $response = Response::where([['id', $data['response_id']], ['status', ResponseStatus::DRAFT]])->first(); if (!$response) { abort(404); } parent::mount($response->id); } protected function getHeaderActions(): array { return [ // ]; } protected function afterSave(): void { $this->record->status = ResponseStatus::SUBMITTED(); $this->record->save(); } public function form(Form $form): Form { $form = static::$resource::form($form, true); return $form; } }
try { $data = JWT::decode(app('request')->input('token'), ['header' => true]); } catch (\Throwable $th) { abort(403); } $response = Response::where([['id', $data['response_id']], ['status', ResponseStatus::DRAFT]])->first(); if (!$response) { abort(404); } parent::mount($response->id); } protected function getHeaderActions(): array { return [ // ]; } protected function afterSave(): void { $this->record->status = ResponseStatus::SUBMITTED(); $this->record->save(); } public function form(Form $form): Form { $form = static::$resource::form($form, true); return $form; } }