Bootstrap 3.1 with laravel 4.0

江枫思渺然 提交于 2019-12-24 13:21:48

问题


I have problem to display confirmation dialog box when I click the delete button it show the confirmation dialog and also submit the form without clicking the button in confirmation dialog box.

I'm using bootstrap and laravel. here is the code.

<div class="modal fade" id="confirmDelete" role="dialog" aria-labelledby="confirmDeleteLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Delete Confirmation</h4>
        </div>
        <div class="modal-body">
            <p>Are you sure you want to delete this data(s) ?</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn default" data-dismiss="modal">Cancel</button>
            <button type="button" class="btn btn-danger" id="confirm">Delete</button>
        </div>
    </div>
</div>

$('#confirmDelete').on('show.bs.modal', function (e) {
            // Pass form reference to modal for submission on yes/ok
            var form = $(e.relatedTarget).closest('form');
            $(this).find('.modal-footer #confirm').data('form', form);
        });

        <!-- Form confirm (yes/ok) handler, submits form -->
        $('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
            $(this).data('form').submit();
        });


{{ Form::open(array('route' => array('subscription.delete.all'), 'method' => 'delete')) }}
<button class='btn btn-xs btn-danger' type='submit' data-toggle="modal" data-target="#confirmDelete">
            <i class='glyphicon glyphicon-trash'></i> Delete
        </button>
{{ Form::close() }}

回答1:


on top of your modal add this

<a href="#" type="button" class="btn btn-default btn-danger" data-toggle="modal" data-target="#confirmDelete">
delete

and in your modal code change the button

<button type="button" class="btn btn-danger" id="confirm">Delete</button>

by your delete button code

    {{ Form::open(array('route' => array('subscription.delete.all')......



回答2:


Change button (inside the form) type from "submit" to "button"



来源:https://stackoverflow.com/questions/23634383/bootstrap-3-1-with-laravel-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!