A dynamic Laravel Livewire component for multi steps form

Overview

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

A dynamic Laravel Livewire component for multi steps form.

Multi steps form

Installation

You can install the package via composer:

composer require vildanbina/livewire-wizard

For UI design this package require WireUI package for details.

Alpine

Livewire Wizard requires Alpine. You can use the official CDN to quickly include Alpine:

">

<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer>script>


<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js">script>

TailwindCSS

The base modal is made with TailwindCSS. If you use a different CSS framework I recommend that you publish the modal template and change the markup to include the required classes for your CSS framework.

php artisan vendor:publish --tag=livewire-wizard-views

Usage

Creating a wizard form

You can create livewire component php artisan make:livewire UserWizard to make the initial Livewire component. Open your component class and make sure it extends the WizardComponent class:



namespace App\Http\Livewire;

use Vildanbina\LivewireWizard\WizardComponent;
use App\Models\User;

class UserWizard extends WizardComponent
{
    // My custom class property
    public $userId;
    
    /*
     * Will return App\Models\User instance or will create empty User (based on $userId parameter) 
     */
    public function model()
    {
        return User::findOrNew($this->userId);
    }
}

When you need to display wizard form, based on above example we need to pass $userId value and to display wizard form:

">
<livewire:user-wizard user-id="3"/>

Or when you want to create new user, let blank user-id attribute, or don't put that.

When you want to reset form, ex. To reset to the first step, and clear filled fields. You can use:

$wizardFormInstance->resetForm();

When you want to have current step instance. You can use:

$wizardFormInstance->getCurrentStep();

When you want to go to specific step. You can use:

$wizardFormInstance->setStep($step);

Or, you want to go in the next step:

$wizardFormInstance->goToNextStep();

Or, you want to go in the prev step:

$wizardFormInstance->goToPrevStep();

Creating a wizard step

You can create wizard form step. Open or create your step class (at App\Steps folder) and make sure it extends the Step class:



namespace App\Steps;

use Vildanbina\LivewireWizard\Components\Step;
use Illuminate\Validation\Rule;

class General extends Step
{
    // Step view located at resources/views/steps/general.blade.php 
    protected string $view = 'steps.general';

    /*
     * Initialize step fields
     */
    public function mount()
    {
        $this->mergeState([
            'name'                  => $this->model->name,
            'email'                 => $this->model->email,
        ]);
    }
    
    /*
    * Step icon 
    */
    public function icon(): string
    {
        return 'check';
    }

    /*
     * When Wizard Form has submitted
     */
    public function save($state)
    {
        $user = $this->model;

        $user->name     = $state['name'];
        $user->email    = $state['email'];
        
        $user->save();
    }

    /*
     * Step Validation
     */
    public function validate()
    {
        return [
            [
                'state.name'     => ['required', Rule::unique('users', 'name')->ignoreModel($this->model)],
                'state.email'    => ['required', Rule::unique('users', 'email')->ignoreModel($this->model)],
            ],
            [
                'state.name'     => __('Name'),
                'state.email'    => __('Email'),
            ],
        ];
    }

    /*
     * Step Title
     */
    public function title(): string
    {
        return __('General');
    }
}

In Step class, you can use livewire hooks example:

use Vildanbina\LivewireWizard\Components\Step;

class General extends Step
{
    public function onStepIn($name, $value)
    {
        // Something you want
    }

    public function onStepOut($name, $value)
    {
        // Something you want
    }

    public function updating($name, $value)
    {
        // Something you want
    }

    public function updatingState($name, $value)
    {
        // Something you want
    }
    
    public function updated($name, $value)
    {
        // Something you want
    }

    public function updatedState($name, $value)
    {
        // Something you want
    }
}

Each step need to have view, you can pass view path in $view property.

After create step class, you need to put that step to wizard form:



namespace App\Http\Livewire;

use App\Steps\General;
use Vildanbina\LivewireWizard\WizardComponent;

class UserWizard extends WizardComponent
{
    public array $steps = [
        General::class,
        // Other steps...
    ];
   
    ...
}

Building Tailwind CSS for production

Because some classes are dynamically build and to compile js you should add some classes to the purge safelist so your tailwind.config.js should look something like this:

module.exports = {
    presets: [
        require("./vendor/wireui/wireui/tailwind.config.js")
    ],
    content: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
        "./resources/**/*.vue",

        "./vendor/vildanbina/livewire-wizard/resources/views/*.blade.php",
        "./vendor/wireui/wireui/resources/**/*.blade.php",
        "./vendor/wireui/wireui/ts/**/*.ts",
        "./vendor/wireui/wireui/src/View/**/*.php"
    ],
    plugins: [
        require("@tailwindcss/forms"),
    ],
};

If you haven't installed tailwindcss/forms plugin, install it: npm install -D @tailwindcss/forms

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please e-mail [email protected] to report any security vulnerabilities instead of the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Adding custom function to the Step to manipulate the state

    Adding custom function to the Step to manipulate the state

    Can you assit i need a way to call the addToCollection function from the step view but it's complain that method not found since i need to maintain all the action that are happening with the step being done in the given Step

    public function mount()
        {
            $this->mergeState([
                'locations' => collect([
                    [
                        'name' => '',
                    ]
                ])
            ]);
        }
    
    

    //

    
     public function addToCollection()
        {
            $this->state['locations']->push(['name' => '']);
        }
    
    
        public function removeFromCollection($key)
        {
            $this->state['locations']->pull($key);
        }
    
    opened by gozbert 5
  • Fix error of method declaration

    Fix error of method declaration

    PHP Fatal error: Declaration of Vildanbina\LivewireWizard\Components\Step::view(string $view): static must be compatible with Illuminate\View\Component::view($view, $data = [], $mergeData = []) in /var/www/html/vendor/vildanbina/livewire-wizard/src/Components/Step.php on line 88

    opened by trippo 1
  • Problems using Laravel 9.36.4

    Problems using Laravel 9.36.4

    With Version 9.36.4 of Laravel i get the following error when trying to show a Wizard:

    Declaration of Vildanbina\LivewireWizard\Components\Step::view(string $view): static must be compatible with Illuminate\View\Component::view($view, $data = [], $mergeData = [])

    opened by JacAppDev 1
  • pass value to parent componenet

    pass value to parent componenet

    Hello and thanks for good package but I want to send some data from Step component to parent Component, how? I was thinking about $this->emit($my_data), but Step extended component does not support it. I want to pass some data to Parent livewire component to Step child component too, is it possible?

    opened by yassermohammad 1
  • Have problem emitting from Javascript inside a step back to the component

    Have problem emitting from Javascript inside a step back to the component

    I am working on a step where the user will be able to take a photo by using the camera. That is already working and the camera shows up and everything. BUT...

    window.livewire.emit('storePhoto', canvas.toDataURL());

    That line is doing nothing and it doesn't matter if I test

    this.Livewire.emit('storePhoto', canvas.toDataURL());

    or...

    Livewire.emit('storePhoto', canvas.toDataURL());

    Nothing happens and yes I have the protected $listeners setup and everything. Do you have any idea why I can't emit data to a function inside a step using the wizard?

    opened by andreaskviby 1
  • Call to undefined function Vildanbina\LivewireWizard\str()

    Call to undefined function Vildanbina\LivewireWizard\str()

    Hey,

    Currently getting an error whenever I attempt to input something into an input field with a wire:model="state.example". I get this error: Call to undefined function Vildanbina\LivewireWizard\str() and it points me to the vendor/vildanbina/livewire-wizard/src/WizardComponent.php page on line 129 where it has $name = str($name);. All I'm doing is using the wire model like I've shown above, and on my save function I have

    $model = $this-model;
    
    $model->example = $state['example'];
    
    $model->save();
    

    and on my validation I'm doing this

    return [
        [
            'state.example' => ['required']
        ],
        [
            'state.example' => __('Example')
        ]
    ]
    

    This is creating a new model/entry so when using the wizard I've left it blank, e.g. <livewire:verify-wizard />.

    opened by CorySheppard 1
  • Add setModel on steps after reset + UI refactoring

    Add setModel on steps after reset + UI refactoring

    • Add setModel on steps after Wizard Instance resetForm
    • Fix step icon centering
    • Decrease the top padding of icons (useful if you must insert into another component like modals)
    • Footer Ui refactor and button labels translations
    • Errors alert below header
    image
    opened by trippo 1
  • Cannot get value of fields in previous steps in the next step.

    Cannot get value of fields in previous steps in the next step.

    Hi, please...how can I get the value of fields in previous steps in the next step? Example: Step 1: input: name Step 2: input: email => (I want to display the name from step one on the page of step 2)

    opened by zeevx 1
  • WireUI Security Patch

    WireUI Security Patch

    As I write on Twitter, update your project to the latest version of the wireui to fix the security issue https://twitter.com/ph7jack/status/1525909343744434176

    opened by PH7-Jack 0
  • Image upload (WithFileUploads) function don't work with livewire-wizard

    Image upload (WithFileUploads) function don't work with livewire-wizard

    When i try to use the script In: Livewire wizardcomponent use Livewire\WithFileUploads; class CreateCampanha extends WizardComponent { use WithFileUploads; public $photo; ... Blade: ... <input type="file" wire:model="photo"> And in Step controller: ` public function save() { $this->validate([ 'photo' => 'image|max:1024', // 1MB Max ]);

        $this->photo->store('photos');
    }
    

    ` But when the send button is pressed it gives this error Call to a member function store() on null this error seems to inform that no file was selected in the input

    opened by luscalopez 0
Releases(v1.2.3)
Owner
Vildan Bina
Experienced Full Stack Engineer with a demonstrated history of working in the information technology and services industry. Skilled in PHP (Laravel), Javascript
Vildan Bina
A dynamic table component for Laravel Livewire - For Slack access, visit:

A dynamic Laravel Livewire component for data tables. Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository Installation You can insta

Anthony Rappa 1.3k Jan 1, 2023
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.

TALL multiselect cards A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards. Table of content

Frederic Habich 19 Dec 14, 2022
A laravel Livewire Dynamic Selects with multiple selects depending on each other values, with infinite levels and totally configurable.

Livewire Combobox: A dynamic selects for Laravel Livewire A Laravel Livewire multiple selects depending on each other values, with infinite levels of

Damián Aguilar 25 Oct 30, 2022
Dynamic Laravel Livewire Bootstrap 5 modals.

Laravel Livewire Modals Dynamic Laravel Livewire Bootstrap 5 modals. Requirements Bootstrap 5 Installation Require the package: composer require basti

null 55 Dec 27, 2022
Dynamic Laravel Livewire Bootstrap toasts.

Laravel Livewire Toasts This package allows you to dynamically show Bootstrap toasts via Laravel Livewire components. Documentation Requirements Insta

null 13 Nov 12, 2022
A Laravel package to help track user onboarding steps.

Onboard A Laravel package to help track user onboarding steps. Installation: Install the package via composer composer require calebporzio/onboard Reg

Caleb Porzio 440 Dec 17, 2022
🧙‍♀️ Arcanist takes the pain out of building multi-step form wizards in Laravel.

Installation Arcanist requires PHP 8 and Laravel 8. composer require laravel-arcanist/arcanist Documentation You can find the full documentation here

Arcanist 378 Jan 3, 2023
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant

The unobtrusive Laravel package that makes your app multi tenant. Serving multiple websites, each with one or more hostnames from the same codebase. B

Tenancy 2.4k Jan 3, 2023
Taskpm - Run multi tasks by PHP multi process

php-pkg-template Run multi tasks by PHP multi process Install composer composer require phppkg/taskpm Usage github: use the template for quick create

PHPPkg 2 Dec 20, 2021
A Multi User Chat Application With Laravel and Livewire

A Multi User Chat Application With Laravel and Livewire. where you can chat with multiple frinds at the same time. i build this with php Laravel and Livewire.

Tauseed 15 Oct 22, 2022
A sample application with a multistep form built with Livewire.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

David Grzyb 11 Nov 26, 2022
Laravel-comments-livewire - Livewire components for the laravel-comments package

Associate comments and reactions with Eloquent models This package contains Livewire components to be used with the spatie/laravel-comments package. S

Spatie 15 Jan 18, 2022
Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

null 22 Oct 6, 2022
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Livewire UI 792 Jan 3, 2023
Laravel Livewire component to show Events in a good looking monthly calendar

Livewire Calendar This package allows you to build a Livewire monthly calendar grid to show events for each day. Events can be loaded from within the

Andrés Santibáñez 680 Jan 4, 2023
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About Wire Elements Spotlight Wire Elements Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel applic

Wire Elements 790 Dec 27, 2022
An advanced datatable component for Laravel Livewire.

Livewire Smart Table An advanced, dynamic datatable component with pagination, sorting, and searching including json data. Installation You can instal

Turan Karatuğ 87 Oct 13, 2022