1

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() and cancel() function so that if the user clicks OK, he gets to the route the button links to, otherwise not.
asked Feb 5, 2017 at 21:23
1
  • how did you done this Commented Mar 7, 2019 at 9:17

1 Answer 1

0

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);
});
answered Feb 5, 2017 at 22:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.