The theme provides options for displaying forms and other Rock content via modals in addition to the standard modal functionality provided by Rock.
In Short
Launch any link within a modal by adding the class js-launch-modal. Use the data attribute data-modal-close-confirmation="true" on the link to prevent the user from accidentally closing the modal. See examples
Keep in mind: All links contained within the modal
will launch inside the modal unless
target attributes are used to open the link on the parent page.
Working with iFrames
To launch a modal from a URL add js-launch-modal to any link. Pages with forms should use the "Full Width Narrow" layout to automatically hide the header, footer, and other page elements when displayed in a modal.
Working with Links
All links found within the modal will launch within the iframe. To cause links to update the parent page either use:
<a href="#" target="_top"></a> to replace the parent page.
<a href="#" target="_blank"></a> to open content in a new page.
Closing Modal from within Iframe
To close the modal from within the iframe use the js-modal-close class on a link:
<a href="#" class="js-modal-close">Close</a>
It's recommended to include a link as a fallback for users that have opened the page outside of a modal.
Close Confirmations
When using with longer, or multi-page forms it's recommended to enable modal-close-confirmation to prevent users from accidentally closing the modal. This will display an additional confirmation message before allowing the user to close the modal.
The close confirmation is not displayed when an element is displayed on the page with one of the following classes:
.js-workflow-entry-message-notification-box.alert-success displayed as a workflow success element
.js-allow-modal-close can be added to any element on a page to allow the page to load.
Options
Options are added via data- attributes, allowing for additional customization of modal behavior.
Name (data-) |
Type |
Default |
Description |
modal-title |
string |
null |
When provided the modal will display with the provided string inside the modal-header before the iframe. |
modal-close-confirmation |
boolean |
false |
When true modal will display a confirmation message before closing. The message is not displayed when a workflow success alert is displayed or an element with js-allow-modal-close is found. |
modal-close-message |
string |
null |
When provided the modal will display the provided string as the modal close confirmation message. Otherwise, "Are you sure you want to exit the form? Your data will be lost if you haven't submitted it." is displayed. |
Methods
The following javascript methods are available for use within the iframe to interact with the parent page:
window.parent.closeModal();
Closes the modal.
window.parent.resizeDynamicModal();
Force the modal to resize.
Example elements used by forms inside of iFrames.