2016-11-30 8 views
0

ハイパーリンクにjquery確認ウィジェットを追加しました。キャンセルをクリックしてもOKの確認モーダルでリンク先にリダイレクトしています。それを制限する方法。ここに私のコードのスニペットmagentoのjquery確認ウィジェット2

htmlファイル

<td class="col id" > 
    <a class="action edit" id="edit" href="<?php /* @escapeNotVerified */ echo $block->getEditUrl($_gridrecord->getEntityId()); ?>" data-ui-id="default-shipping-edit-link"> 
    <span> 
     <?php /* @escapeNotVerified */ echo __('Edit'); ?> 
    </span> 
    </a> 

jqueryのスクリプト

<script type="text/javascript">// <![CDATA[ 
require([ 
     'jquery', 
     'Magento_Ui/js/modal/confirm' 
    ], 
    function($, confirmation) { 
     $('#edit').on('click', function(event){ 
       confirmation({ 
      title: 'Some title', 
      content: 'Some content', 
      actions: { 
       confirm: function(){}, 
       cancel: function(){ 
        return false; 
       }, 
       always: function(){} 
      } 
      }); 
     }); 
     } 
); 
// ]]></script> 

答えて

0

はこれを試してみてくださいされています

<script type="text/javascript">// <![CDATA[ 
require([ 
     'jquery', 
     'Magento_Ui/js/modal/confirm' 
    ], 
    function($, confirmation) { 
     $('#edit').on('click', function(event){ 
      event.preventDefault; 
       confirmation({ 
      title: 'Some title', 
      content: 'Some content', 
      actions: { 
       confirm: function(){}, 
       cancel: function(){ 
        return false; 
       }, 
       always: function(){} 
      } 
      }); 
     }); 
     } 
); 
// ]]></script> 

または

<script type="text/javascript">// <![CDATA[ 
require([ 
     'jquery', 
     'Magento_Ui/js/modal/confirm' 
    ], 
    function($, confirmation) { 
     $('#edit').on('click', function(event){ 
       confirmation({ 
      title: 'Some title', 
      content: 'Some content', 
      actions: { 
       confirm: function(){}, 
       cancel: function(){ 
        return false; 
       }, 
       always: function(){} 
      } 
      return false; 
      }); 
     }); 
     } 
); 
// ]]></script> 

これはあなたのリンクにリダイレクトされません。

+0

いないが、平行で起こっていることはできません。 –

+0

誰でもjqueryウィジェットのサンプルコードをmagento 2で共有してください。 –

1

このようなものが必要です。

<script type = 'text/javascript'> 
    require([ 
      'jquery', 
      'Magento_Ui/js/modal/confirm' 
     ], 
     function ($, confirmation) { 
     $('.cancel').click(function (event) { 
      event.preventDefault(); 

      var url = event.currentTarget.href; 
      confirmation({ 
       title: 'Cancel order', 
       content: 'Do you wish to cancel this order?', 
       actions: { 
        confirm: function() { 
         window.location.href = url; 
        }, 
        cancel: function() {}, 
        always: function() {} 
       } 
      }); 
      return false; 
     }); 
    }); 
</script> 

キーはevent.preventDefault();return falseを呼び出すことです。これをコールバックから行うことはできません。これはイベントを終了させるので、あなたはURLを取得して確認コールバックのために保存する必要があります。この例では、magento CE 2.1.7でチェックされたキャンセル注文ボタンに確認を追加します。

アビシェークダンラージShahdeoと同様の答えが、私は編集したり、コメントはまだそう... working.actullyリンクにリダイレクトし、このモーダルボックスを示していない

+0

はい@chris lingwoodあなたが正しいです、キーはevent.preventDefault()です。 –

関連する問題