Download the PHP package tofandel/inertia-vue-modal without Composer
On this page you can find all versions of the php package tofandel/inertia-vue-modal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tofandel/inertia-vue-modal
More information about tofandel/inertia-vue-modal
Files in tofandel/inertia-vue-modal
Package inertia-vue-modal
Short Description Display any inertia page in a modal
License GPL-3.0-or-later
Informations about the package inertia-vue-modal
Inertia Vue Modal
Warning
I stopped development of this package and will not be using it anymore, there is a lot of issues with it and it is definitely not something I'd recommend using in production. Have a look at momentum-modal for an alternative or hybridly for complete inertia alternative (and much more)
Warning
Limitations
This POC is a very early draft, so these limitations will probably be fixed soon.
- No support for nested modals (modal in modal)
- It doesn't use browser history navigation
Installation
Client-side installation
In your layout, you need to add the InertiaModal
component, here is an example using the Quasar Dialog
Axios dependency
It's very important that your project only uses one version of axios because of the use of interceptors, if you use webpack and your packages have conflicting versions of axios they will each be bundled separately and interceptors won't work To resolve this issue make sure that you add this to your webpack.config.js
Server-side installation
In your Laravel application, you need to extend our HandlesInertiaModalRequest middleware
Usage
Since we added the InertiaModal
component, the global $inertia
object now has a visitInModal
method. This allows you to make an Inertia visit that loads into the modal.
You can use this method, for example, in the @click
handler of a button:
Instead of using the method in your template, you can also use it in your script:
Update the page you want to load into a modal
In most cases, the /user/create
endpoint renders a form that's wrapped into a template, maybe with other components and components to style the form. Here's a simple example of what the UserCreate.vue
component might look like:
To load this form into a modal, we don't want the sidebar, footer, and styling from the form-panel
component. We want just the form
itself!
To accomplish this, you need to do three things:
- Add the
IsModalable
mixin to your component. - Wrap your whole component into the
Modalable
component. - Move the
form
to a separate#toModal
template and replace it with aToModal
component.
Now when you visit /user/create
, nothing has changed! You still have your layout and form-panel
styling. But when you load this component into a modal, it will only render the form
.
Handling redirects
By default, redirects are handled as any other Inertia request. For example you're visiting /user
, you open /user/create
in a modal, and after a successful submit, you redirect the user to the detail page of the newly created user:
You might not always want to route to the detail page. Luckily, you don't have to update your server-side implementation.
The visitInModal
method accepts a second argument that can either a Boolean or a callback. Instead of redirecting the user, the user stays on the same page, and you can manually handle the event with the callback. This callback is executed after a successful request, for example, when the new user is stored in the database.