Introduction
Actions may require additional confirmation or input from the user before they run. You may open a modal before an action is executed to do this.Confirmation modals
You may require confirmation before an action is run using therequiresConfirmation() method. This is useful for particularly destructive actions, such as those that delete records.
Confirmation modals use the
alertdialog ARIA role instead of dialog, so screen readers announce them as alerts and automatically read the modalâs description when they open.Controlling modal content
Customizing the modalâs heading, description, and submit action label
You may customize the heading, description and label of the submit button in the modal:Rendering a schema in a modal
Filament allows you to render a schema in a modal, which allows you to render any of the available components to build a UI. Usually, it is useful to build a form in the schema that can collect extra information from the user before the action runs, but any UI can be rendered:Rendering a form in a modal
You may use form field to create action modal forms. The data from the form is available in the$data array of the action() closure:
Filling the form with existing data
You may fill the form with existing data, using thefillForm() method:
Disabling all form fields
You may wish to disable all form fields in the modal, ensuring the user cannot edit them. You may do so using thedisabledForm() method:
Rendering a wizard in a modal
You may create a multistep form wizard inside a modal. Instead of using aschema(), define a steps() array and pass your Step objects:
Adding an icon inside the modal
You may add an icon inside the modal using themodalIcon() method:
modalIconColor() method:
Customizing the alignment of modal content
By default, modal content will be aligned to the start, or centered if the modal isxs or sm in width. If you wish to change the alignment of content in a modal, you can use the modalAlignment() method and pass it Alignment::Start or Alignment::Center:
Making the modal header sticky
The header of a modal scrolls out of view with the modal content when it overflows the modal size. However, slide-overs have a sticky header thatâs always visible. You may control this behavior usingstickyModalHeader():
Making the modal footer sticky
The footer of a modal is rendered inline after the content by default. Slide-overs, however, have a sticky footer that always shows when scrolling the content. You may enable this for a modal too usingstickyModalFooter():
Custom modal content
You may define custom content to be rendered inside your modal, which you can specify by passing a Blade view into themodalContent() method:
Passing data to the custom modal content
You can pass data to the view by returning it from a function. For example, if the$record of an action is set, you can pass that through to the view:
Adding custom modal content below the form
By default, the custom content is displayed above the modal form if there is one, but you can add content below usingmodalContentFooter() if you wish:
Adding an action to custom modal content
You can add an action button to your custom modal content, which is useful if you want to add a button that performs an action other than the main action. You can do this by registering an action with theregisterModalActions() method, and then passing it to the view:
getModalAction():
Using a slide-over instead of a modal
You can open a âslide-overâ dialog instead of a modal by using theslideOver() method:
Changing the slide-over position
By default, slide-overs enter from the end of the screen (the right side in left-to-right languages, the left side in right-to-left languages). You may change this to the start of the screen by passingSlideOverPosition::Start to the slideOverPosition() method:
Changing the modal width
You can change the width of the modal by using themodalWidth() method. Options correspond to Tailwindâs max-width scale. The options are ExtraSmall, Small, Medium, Large, ExtraLarge, TwoExtraLarge, ThreeExtraLarge, FourExtraLarge, FiveExtraLarge, SixExtraLarge, SevenExtraLarge, and Screen:
Executing code when the modal opens
You may execute code within a closure when the modal opens, by passing it to themountUsing() method:
ThemountUsing()method, by default, is used by Filament to initialize the form. If you override this method, you will need to call$form->fill()to ensure the form is initialized correctly. If you wish to populate the form with data, you can do so by passing an array to thefill()method, instead of usingfillForm()on the action itself.
Customizing the action buttons in the footer of the modal
By default, there are two actions in the footer of a modal. The first is a button to submit, which executes theaction(). The second button closes the modal and cancels the action.
Modifying the default modal footer action button
To modify the action instance that is used to render one of the default action buttons, you may pass a closure to themodalSubmitAction() and modalCancelAction() methods:
$action instance inside the closure.
Removing a default modal footer action button
To remove a default action, you may passfalse to either modalSubmitAction() or modalCancelAction():
Adding an extra modal action button to the footer
You may pass an array of extra actions to be rendered, between the default actions, in the footer of the modal using theextraModalFooterActions() method:
$action->makeModalSubmitAction() returns an action instance that can be customized using the methods available to customize trigger buttons.
The second parameter of makeModalSubmitAction() allows you to pass an array of arguments that will be accessible inside the actionâs action() closure as $arguments. These could be useful as flags to indicate that the action should behave differently based on the userâs decision:
Opening another modal from an extra footer action
You can nest actions within each other, allowing you to open a new modal from an extra footer action:edit action, and will not run the edit action when it is clicked.
In this example though, you probably want to cancel the edit action if the delete action is run. You can do this using the cancelParentActions() method:
cancelParentActions():
fourth action is run, the second action is canceled, but so is the third action since it is a child of second. The first action is not canceled, however, since it is the parent of second. The first actionâs modal will remain open.
Accessing information about parent actions from a child
You can access the instances of parent actions and their raw data and arguments by injecting the$mountedActions array in a function used by your nested action. For example, to get the top-most parent action currently active on the page, you can use $mountedActions[0]. From there, you can get the raw data for that action by calling $mountedActions[0]->getRawData(). Please be aware that raw data is not validated since the action has not been submitted yet:
$mountedActions[0]->getArguments() method.
Even if you have multiple layers of nesting, the $mountedActions array will contain every action that is currently active, so you can access information about them:
Closing the modal
Closing the modal by clicking away
By default, when you click away from a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use thecloseModalByClickingAway(false) method:
ModalComponent::closedByClickingAway() inside a service provider or middleware:
Closing the modal by escaping
By default, when you press escape on a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use thecloseModalByEscaping(false) method:
ModalComponent::closedByEscaping() inside a service provider or middleware:
Hiding the modal close button
By default, modals have a close button in the top right corner. If you wish to hide the close button, you can use themodalCloseButton(false) method:
ModalComponent::closeButton(false) inside a service provider or middleware:
Making the modal click-through
By default, a modal blocks interaction with the rest of the page while it is open. If you want the user to be able to keep interacting with the page behind the modal, you can make it âclick-throughâ using themodalClickThrough() method:
A click-through modal cannot be closed by clicking away, as that would be incompatible with interacting with the page behind it. Enabling
modalClickThrough() therefore disables closing by clicking away automatically.Preventing the modal from autofocusing
By default, modals will autofocus on the first focusable element when opened. If you wish to disable this behavior, you can use themodalAutofocus(false) method:
ModalComponent::autofocus(false) inside a service provider or middleware:
Overlaying child action modals on top of parent action modals
By default, when a child action opens its modal, the parent actionâs modal is temporarily closed and then reopened after the child action is dismissed. If youâd like the child actionâs modal to instead appear on top of the parent actionâs modal (keeping the parent visible underneath), you can use theoverlayParentActions() method on the child action:
Canceling parent actions when a modal is closed
ThecancelParentActions() method above only cancels parent actions when the child action is run. If the user closes the childâs modal instead â by pressing Escape, clicking the backdrop, or using the close button â by default only that modal is closed, leaving any parent actions still mounted. To also cancel parent actions when the modal is closed, allowing the user to abandon a multi-step flow entirely rather than closing one modal at a time, use the cancelParentActionsOnClose() method:
saveAsDraft modal will also cancel the createPost action and close its modal.
Like cancelParentActions(), you can pass the name of a parent action to cancel back to a specific parent, including its children, rather than all of them:
Optimizing modal configuration methods
When you use database queries or other heavy operations inside modal configuration methods likemodalHeading(), they can be executed more than once. This is because Filament uses these methods to decide whether to render the modal or not, and also to render the modalâs content.
To skip the check that Filament does to decide whether to render the modal, you can use the modal() method, which will inform Filament that the modal exists for this action, and it does not need to check again:
Conditionally hiding the modal
You may have a need to conditionally show a modal for confirmation reasons while falling back to the default action. This can be achieved usingmodalHidden():
Adding extra attributes to the modal window
You can pass extra HTML attributes to the modal window via theextraModalWindowAttributes() method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
Adding extra attributes to the modal overlay
You can pass extra HTML attributes to the modal overlay via theextraModalOverlayAttributes(). The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value: