Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

Prompt Widget in Magento 2: What Is It & How to Initialize?

Vinh Jacker | 12-18-2024

Prompt Widget in Magento 2: What Is It & How to Initialize?

Prompt Widget Magento 2 allows showing a modal pop-up window with an input field, and a cancel and a confirmation button and it also extends the Magento modal widget. The origin of Magento 2 prompt widget is <Magento_Ui_module_dir>/view/base/web/js/modal/prompt.js.

Using the Magento 2 Widget means you can work with the prompt window for Admin and storefront. By this way, the design patterns for the modal pop-up windows in the Admin are defined in the Magento Admin Pattern Library, the Slide-out Panels, Modal Windows, and Overlays topic.

Initialize Prompt Widget

There are two ways to initialize the Magento 2 prompt widget

Initialization on an element

$('#prompt_init').prompt({
    title: 'Prompt title',
    actions: {
        confirm: function(){}, //callback on 'Ok' button click
        cancel: function(){}, //callback on 'Cancel' button click
        always: function(){}
    }
});

Standalone Initialization

require([
    'Magento_Ui/js/modal/prompt'
], function(prompt) { // Variable that represents the `prompt` function
 
    prompt({
        title: 'Some title',
        content: 'Some content',
        actions: {
            confirm: function(){},
            cancel: function(){},
            always: function(){}
        }
    });
 
});

Prompt Widget Options

actions

Widget callbacks.

  • Type: Object.

  • Default value:

actions: {
    confirm: function(){},
    cancel: function(){},
    always: function(){}
}

autoOpen

Automatically open the prompt window when the widget is initialized.

  • Type: Boolean

  • Default value: false

clickableOverlay

Close the prompt window when a user clicks on the overlay.

Type: Boolean

Default value: true

content

The prompt window content.

  • Type: String.

focus

Allow focusing on the selector of the element if the prompt window opens. In case the focusoption is not specificed or empty, the focus is on the close button. And if the focus is optional, please set focus to none.

  • Type: String.

  • Default value: ''

title

The title of the prompt window.

  • Type: String.

  • Default value: ''

Related Post

x
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services