To add a save button inside a wizard step in a Filament form, you can customize the wizard steps and include a save button within the step content. Here's a basic example of how you can achieve this:
- Create a Filament Form with Wizard Steps:
First, ensure you have a Filament form with wizard steps set up. Here's a basic example:
use Filament\Forms;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Components\Wizard\Step;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Button;
class MyForm extends Forms\Component
{
public function getFormSchema(): array
{
return [
Wizard::make([
Step::make('Step 1')
->schema([
TextInput::make('name')
->required(),
// Add a save button within the step
Button::make('Save')
->action('save')
->type('submit')
->color('primary'),
]),
Step::make('Step 2')
->schema([
TextInput::make('email')
->required(),
// Add a save button within the step
Button::make('Save')
->action('save')
->type('submit')
->color('primary'),
]),
]),
];
}
public function save()
{
// Handle the save action
$data = $this->form->getState();
// Save the data to the database or perform other actions
}
}
- Explanation:
- Wizard::make: This creates the wizard component.
- Step::make: This defines each step in the wizard.
- TextInput::make: This adds a text input field to the form.
-
Button::make: This adds a button to the form. The
actionmethod specifies the method to call when the button is clicked. Thetype('submit')ensures the button submits the form.
- Save Method:
The save method is where you handle the form submission. You can access the form data using $this->form->getState() and then save it to the database or perform other actions as needed.
- Styling and Positioning:
You can further customize the styling and positioning of the button using Filament's built-in methods or by adding custom CSS classes.
This example should give you a good starting point for adding a save button within a wizard step in a Filament form. You can adjust the schema and actions according to your specific requirements.