Dear team,
I want Magento UI with an alert message before clearing the item in the shopping cart. I have used below code in
\vendor\magento\module-checkout\view\frontend\templates\cart\form.phtml
Without clicking Ok or Cancel button its automatically clear the data and redirected. Can anyone help me
Browser alert will be working good. but I need an alert message with Magento UI.
My Code is below:
<button type="submit"
name="update_cart_action"
data-cart-empty=""
value="empty_cart"
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
class="action clear" id="empty_cart_button">
<span><?= /* @escapeNotVerified */ __('Clear Shopping Cart') ?></span>
</button>
<script type="text/javascript">
require(['jquery','Magento_Ui/js/modal/confirm'], function ($, confirm) {
$('.clear').on("click",function(event){
event.stopPropagation();
//event.preventDefault()
confirm({
content: 'Are you sure you would like to remove these item from the shopping cart?',
actions: {
confirm: function () {
return true;
},
cancel: function (event) {
return false;
}
}
});
});
});
</script>