I have an extension with a backend view where I have a button which routes to another url. When the user clicks the button I want to show a pop up which asks him a second time if he/she really wants to continue. I have the following code in my template:
<button class="action-third" type="submit" title="Reset" id="reset-all" onclick="setLocation('<?php echo $block->getUrl('some/url/reset') ?>')">
<span>Reset all</span>
</button>
<script type="text/javascript">// <![CDATA[
require([
'jquery',
'Magento_Ui/js/modal/confirm'
], function(,ドル confirmation) {
$('#reset-all').on('click', 'button.action-third', function(event){
confirmation({
title: 'Reset...',
content: 'Do you really want to reset?',
actions: {
confirm: function(){},
cancel: function(){},
always: function(){}
}
});
})
});
// ]]></script>
</div>
But that does not work. Here are my two questions:
- What do I have to do so that the pop up shows up?
- What should I insert in the
confirm()andcancel()function so that if the user clicks OK, he gets to the route the button links to, otherwise not.
-
how did you done thisJaisa– Jaisa2019年03月07日 09:17:53 +00:00Commented Mar 7, 2019 at 9:17
1 Answer 1
If you are in adminhtml area then you can use confirmSetLocation() function in javascript like this:
var url = '<?php echo $block->getUrl('some/url/reset') ?>';
$('#reset-all').on('click', 'button.action-third', function(event){
confirmSetLocation('Do you really want to reset?', url);
});
Explore related questions
See similar questions with these tags.