Search.../

openModal( )

Description

This function can only be used in page code files for dashboard pages created in the Wix editor or with Wix Blocks.

The openModal() function returns an object with a property called modalClosed. This property is a promise that resolves to the data passed to closeModal() when the modal is closed.

Note: Before you use this function, you need a dashboard modal extension. Learn more about implementing dashboard modal extensions.

Syntax

function openModal(modalId: string, [modalParams: Object]): OpenModalReturn

openModal Parameters

NAME
TYPE
DESCRIPTION
modalId
string

ID of the dashboard modal extension to open.

modalParams
Optional
Object

Custom data to pass into the extension. The extension can access this data using observeState().

Returns

Return Type:

OpenModalReturn
NAME
TYPE
DESCRIPTION
modalClosed
Promise<Serializable>

Resolves to the data passed to closeModal() when the modal is closed.

Was this helpful?

Open a modal and log the data returned when it's closed

Copy Code
1import { openModal } from 'wix-dashboard';
2
3/* Sample modalID: '1d52d058-0392-44fa-bd64-ed09275a6fcc' */
4
5const { modalClosed } = openModal('myModalId')
6
7modalClosed
8 .then((closeData) => {
9 console.log('The modal was closed and returned: ', closeData);
10 })
11 .catch((error) => {
12 console.error(error);
13 // Handle the error
14 });
15
16/* The value of `modalClosed` resolves to an object containing the data passed in when the modal is closed. */
Pass data to a modal extension

Copy Code
1import { openModal } from 'wix-dashboard';
2
3/* Sample modalID value: '1d52d058-0392-44fa-bd64-ed09275a6fcc'
4 * Sample modalParams value
5 * {
6 * firstName: 'Name'
7 * }
8 */
9
10const { modalClosed } = client.dashboard.openModal('myModalId', myModalParams)
11
12modalClosed
13 .then((closeData) => {
14 console.log('The modal was closed and returned: ', closeData);
15 })
16 .catch((error) => {
17 console.error(error);
18 // Handle the error
19 });
20
21/* The value of `modalClosed` resolves to an object containing the data passed in when the modal is closed. */