rinodrummer/livewire-wizard-form
Installation
composer require rinodrummer/livewire-wizard-form
Publish the config (if needed):
php artisan vendor:publish --provider="RinoDrummer\LivewireWizardForm\LivewireWizardFormServiceProvider"
First Use Case: Basic Wizard Form
Create a Livewire component with the HasWizardForm trait:
use RinoDrummer\LivewireWizardForm\Traits\HasWizardForm;
class MultiStepForm extends Component
{
use HasWizardForm;
public function mount()
{
$this->wizardForm()->steps([
'step1' => 'Step 1',
'step2' => 'Step 2',
'step3' => 'Step 3',
]);
}
public function render()
{
return view('livewire.multi-step-form');
}
}
Blade Integration Use the provided directives in your view:
@wizardForm
@wizardStep('step1')
<!-- Step 1 content -->
@endwizardStep
@wizardStep('step2')
<!-- Step 2 content -->
@endwizardStep
Navigation Add buttons to control flow:
@wizardPreviousButton
@wizardNextButton
@wizardSubmitButton
Step Management Dynamically add/remove steps via methods:
$this->wizardForm()->addStep('new_step', 'New Step');
$this->wizardForm()->removeStep('step2');
Validation Integration
Use validateStep() to enforce validation per step:
public function nextStep()
{
$this->validateStep('step1', [
'email' => 'required|email',
]);
$this->wizardForm()->next();
}
Data Persistence Bind form data to properties:
public $step1Data = [];
public $step2Data = [];
protected $rules = [
'step1Data.*' => 'required',
'step2Data.*' => 'required',
];
Custom Logic per Step
Override onStepEnter()/onStepLeave():
public function onStepEnter($stepName)
{
if ($stepName === 'step3') {
$this->fetchAdditionalData();
}
}
Conditional Steps Hide/show steps dynamically:
public function render()
{
return view('livewire.multi-step-form')->with([
'showStep3' => $this->shouldShowStep3(),
]);
}
Progress Tracking
Use $this->wizardForm()->currentStep() and $this->wizardForm()->progress() in Blade:
Progress: {{ $this->wizardForm()->progress() }}%
Multi-Form Integration Combine with other Livewire components:
public function mount()
{
$this->wizardForm()->steps(['step1', 'step2']);
$this->otherComponent = new OtherComponent();
}
State Management
session() or database to persist progress:
public function mount()
{
$this->wizardForm()->steps(['step1', 'step2']);
$this->wizardForm()->setCurrentStep(session('wizard_step', 'step1'));
}
public function nextStep()
{
session(['wizard_step' => $this->wizardForm()->currentStep()]);
}
Validation Quirks
public function nextStep()
{
$this->resetErrorBag();
$this->validateStep('step1', [...]);
}
Blade Directive Scope
@wizardStep directives must be nested inside @wizardForm.@wizardForm
@wizardStep('step1') <!-- Correct -->
<!-- Content -->
@endwizardStep
@endwizardForm
Performance with Many Steps
@wizardStep('step1')
@livewire('step1-content', key($this->wizardForm()->currentStep()))
@endwizardStep
dd($this->wizardForm()->currentStep());
dd($this->rules);
dd($this->wizardForm()->getState());
Custom Transitions
Override transitionToStep():
protected function transitionToStep($stepName)
{
// Custom logic (e.g., analytics, logging)
parent::transitionToStep($stepName);
}
Step Templates Create reusable step templates:
@component('wizard.step-template', ['step' => $step])
@slot('content')
<!-- Dynamic content -->
@endslot
@endcomponent
Event Listeners Listen to step changes:
$this->wizardForm()->on('stepChanged', function ($step) {
// Handle step change
});
Theming Override default styles via CSS:
.wizard-step.active {
background: #your-color;
}
How can I help you explore Laravel packages today?