Persist modal text field data after close the modal.

Here I have to change the status from from and If I change the status then a modal is open and ask for description. I want to show that description in my form somewhere after modal close. How to do that in filament ?
No description
Solution:
placeholder doesn't have a state.. I think you could add an attribute in the EditPage and use it to set the value
public $description = null;
public $description = null;
...
Jump to solution
8 Replies
LeandroFerreira
LeandroFerreira7mo ago
Could you share some code that you are using?
Asmit Nepali
Asmit NepaliOP7mo ago
Section::make('Submission Status')
->schema([
Select::make('status')
->enum(Status::class)
->live()
->required()
->options(Status::class)
->registerActions([
Action::make('addNoteOnStatusUpdated')
->label(function ($state) {
return Status::from($state)->getLabel();
})
->form([
Textarea::make('description')
->label('Reason')
->required(),
])
->action(function ($record, $data) {
$record->notes()->create([
'description' => $data['description'],
'user_id' => auth()->id(),
]);
}),
])
->default(Status::SUBMITTED)
->afterStateUpdated(function ($livewire, Component $component, $state) {
return $livewire->mountFormComponentAction($component->getStatePath(), 'addNoteOnStatusUpdated');
}),
])->hiddenOn(['create'])
Section::make('Submission Status')
->schema([
Select::make('status')
->enum(Status::class)
->live()
->required()
->options(Status::class)
->registerActions([
Action::make('addNoteOnStatusUpdated')
->label(function ($state) {
return Status::from($state)->getLabel();
})
->form([
Textarea::make('description')
->label('Reason')
->required(),
])
->action(function ($record, $data) {
$record->notes()->create([
'description' => $data['description'],
'user_id' => auth()->id(),
]);
}),
])
->default(Status::SUBMITTED)
->afterStateUpdated(function ($livewire, Component $component, $state) {
return $livewire->mountFormComponentAction($component->getStatePath(), 'addNoteOnStatusUpdated');
}),
])->hiddenOn(['create'])
LeandroFerreira
LeandroFerreira7mo ago
where would you like to show the description?
Asmit Nepali
Asmit NepaliOP7mo ago
@Leandro Ferreira Let's say I set status decline then I have to add description (reason) for that. But the description is fill on the modal, after modal colse I have show that description on the form placeholder
LeandroFerreira
LeandroFerreira7mo ago
maybe this?
Placeholder::make('note')
->content(fn(?YourModel $record) => $record?->notes?->last()?->description)
Placeholder::make('note')
->content(fn(?YourModel $record) => $record?->notes?->last()?->description)
Asmit Nepali
Asmit NepaliOP7mo ago
Ya I also think about this but it will more reliable if we able to get the current notes from the form components it self rather than fetching from DB
Solution
LeandroFerreira
LeandroFerreira7mo ago
placeholder doesn't have a state.. I think you could add an attribute in the EditPage and use it to set the value
public $description = null;
public $description = null;
Placeholder::make('notes')
->content(fn($livewire) => $livewire->description)
Placeholder::make('notes')
->content(fn($livewire) => $livewire->description)
->action(function ($record, $data, $livewire) {

$description = $data['description'];

$record->notes()->create([
'description' => $description,
'user_id' => auth()->id(),
]);

$livewire->description = $description;
})
->action(function ($record, $data, $livewire) {

$description = $data['description'];

$record->notes()->create([
'description' => $description,
'user_id' => auth()->id(),
]);

$livewire->description = $description;
})
Asmit Nepali
Asmit NepaliOP7mo ago
@Leandro Ferreira It works Thank you!
Want results from more Discord servers?
Add your server