Magento 2.x – Using Confirmation and Alert Jquery Widget popups
In some cases you will need to show a confirmation modal popup, or an alert. To make it Magento way, i will show you some pretty usefull javascript code snippets:
Confirmation popup:
The Magento confirmation widget implements a modal pop-up window with the cancel and confirmation button. You can use it with the following snippet in your javascript code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
require([ 'Magento_Ui/js/modal/confirm' ], function(confirm) { // Variable that represents the `confirm` widget confirm({ title: 'Title', content: 'Content', actions: { confirm: function(){}, cancel: function(){}, always: function(){} } }); }); |
Source: <Magento_Ui_module_dir>/view/base/web/js/modal/confirm.js
Alert popup:
The Magento alert widget implements a modal pop-up window with a confirmation button. You can use it with the following snippet in your javascript code:
1 2 3 4 5 6 7 8 9 10 11 12 |
require([ 'Magento_Ui/js/modal/alert' ], function(alert) { alert({ title: 'Title', content: 'Content', actions: { always: function(){} } }); }); |
Source: <Magento_Ui_module_dir>/view/base/web/js/modal/alert.js
Before testing, remember to redeploy your static content.
Thanks for reading! Happy coding.!