2017-12-05 1 views
0

モーダル検証した後にのみ提出します。 そして、私は現在のアイテムフォームは、私は私のフォームを作成する<a href="https://laravelcollective.com/docs/5.4/html" rel="nofollow noreferrer">this package</a>を使用してい

{!! Form::open(['method' => 'delete', 'url' => route($entity.'.destroy', [$entity => $id]), 'style' => 'display: inline', 'onSubmit' => 'confirm("Do you really want to delete that?")']) !!} 
    <button type="submit" class="btn-delete btn btn-xs btn-danger"> 
     <i class="glyphicon glyphicon-trash"></i> 
    </button> 
{!! Form::close() !!} 

のsuppresionを確認するために、このコードを使用していますこれは正常に動作しますが、私はこの醜いJSは、だから私はこの

を試してみましたモーダル

によって確認交換したいと思います

{!! Form::open(['method' => 'delete', 'url' => route($entity.'.destroy', [$entity => $id]), 'style' => 'display: inline', 'onSubmit' => '$("#modal_' . $id. '").modal("show");']) !!} 
    <button type="submit" class="btn-delete btn btn-xs btn-danger"> 
     <i class="glyphicon glyphicon-trash"></i> 
    </button> 
{!! Form::close() !!} 


<!-- Modal --> 
<div id="modal_{{ $id }}" class="modal fade" role="dialog"> 
    <div class="vertical-alignment-helper"> 
     <div class="modal-dialog vertical-align-center"> 
      <div class="modal-content"> 
       <div class="modal-body"> 
        <button type="button" class="close" data-dismiss="modal">&times;</button> 
        <p>You are about to delete.</p> 
        <p>Do you want to proceed?</p> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-primary pull-left" data-dismiss="modal">Cancel</button>     
        <button type="button" class="btn btn-danger"> 
         <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Confirm 
        </button> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

しかし、アイテムがモーダル上の任意のクリックする前に削除されます。

このパッケージを使用してモーダルを適切にトリガーすることは可能ですか、古い学校のhtmlフォームを作成するだけですか?

+1

? – zack6849

+0

@ zack6849それは解決策になるかもしれませんが、この種の機能が 'laravelcollective/html'で可能かどうかを尋ねています...そうでなければ、AJAXの解決策に挑戦します! – Raccoon

答えて

0

フォームパッケージの目的は、ちょうどあなたがHTMLのフォーム要素の作成を支援することです。普通のHTMLフォームのパッケージを変更すると、同じ結果が得られます。なぜなら、PHPの助けを借りてhtmlで書かれたものと同じ要素タグを生成するからです。

最初のボタンを変更してモーダルをトリガーし、モーダル確定ボタンを使用してフォームを送信すると機能します。フォームがどこにも行かなかったし、ちょうどあなたのモーダルをトリガし、そのモーダルがそれを確認すると、実際の削除フォームに投稿するAJAXを使用した、onclickを持っていないのはなぜ

<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modal_{{ $id }}"> 
    <i class="glyphicon glyphicon-trash"></i> 
</button> 

<!-- Modal --> 
<div id="modal_{{ $id }}" class="modal fade" role="dialog"> 
    <div class="vertical-alignment-helper"> 
     <div class="modal-dialog vertical-align-center"> 
      <div class="modal-content"> 
       <div class="modal-body"> 
        <button type="button" class="close" data-dismiss="modal">&times;</button> 
        <p>You are about to delete.</p> 
        <p>Do you want to proceed?</p> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-primary pull-left" data-dismiss="modal">Cancel</button>     
        {!! Form::open(['method' => 'delete', 'url' => route($entity . '.destroy', [$entity => $id]) ]) !!} 
         <button type="submit" class="btn-delete btn btn-xs btn-danger"> 
          <i class="glyphicon glyphicon-trash"></i> 
         </button> 
        {!! Form::close() !!} 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
+0

ありがとう!それは完全に動作します! – Raccoon

関連する問題

 関連する問題