composer require anish/clearfield-action in your Laravel project.ClearFieldAction::make() to your getHeaderActions() method in either CreateRecord or EditRecord pages.Actions/ClearFieldAction.php for core logic and available methods.Standard Reset Button:
ClearFieldAction::make()
->label('Reset Form')
->icon('heroicon-o-arrow-path')
->color('gray');
Confirmation-Driven Reset:
ClearFieldAction::make()
->requiresConfirmation()
->confirmationTitle('Reset All Fields?')
->confirmationDescription('This will clear all entered data.')
->successNotificationTitle('Form Reset')
->successNotificationDescription('All fields have been cleared.');
Conditional Reset with Callbacks:
ClearFieldAction::make()
->before(function () {
// Pre-reset logic (e.g., log event, validate unsaved changes)
event(new FormResetAttempted());
})
->after(function () {
// Post-reset logic (e.g., focus first field, reset dependent dropdowns)
$this->focusField('first_name');
});
Dynamic Labeling:
ClearFieldAction::make()
->label(fn (CreateUser $page) => $page->record ? 'Clear Changes' : 'Reset Form');
ResetForm for programmatic resets in custom logic.->visible(fn () => auth()->user()->can('manage_users'));
->label(__('actions.reset_form'))
->confirmationTitle(__('actions.reset_confirm.title'));
Field-Specific Reset Issues:
RichEditor, FileUpload) may not reset cleanly due to internal state.after callback to manually reset:
->after(function () {
$this->fillForm([
'rich_editor_field' => null,
'file_upload_field' => null,
]);
});
Confirmation Dialog Overlap:
requiresConfirmation() may cause UI clutter.Performance with Large Forms:
after callback:
->after(function () {
$this->dispatchBrowserEvent('reset-form-batched');
});
Filament Version Mismatch:
composer.json for version constraints and test in a staging environment.config/filament.php) to log action execution:
'debug' => env('FILAMENT_DEBUG', false),
$this->actingAs($user)
->get($resource->getCreateRecordRoute())
->assertSee('Reset Form');
Custom Reset Logic:
use Anish\ClearFieldAction\Actions\ClearFieldAction;
class CustomClearFieldAction extends ClearFieldAction {
protected function performAction(): void {
// Custom logic (e.g., soft-reset specific fields)
$this->fillForm(['field_to_preserve' => 'default_value']);
}
}
Global Configuration:
php artisan vendor:publish --tag="clearfield-action-config") to set defaults:
'default_confirmation' => false,
'default_notification' => true,
Blade Templates:
php artisan vendor:publish --tag="clearfield-action-views"
resources/views/vendor/clearfield-action/confirmation.blade.php or notification.blade.php.Event Listeners:
use Anish\ClearFieldAction\Events\FormReset;
FormReset::listen(function (FormReset $event) {
Log::info('Form reset triggered by user', ['user_id' => auth()->id()]);
});
How can I help you explore Laravel packages today?