Why doesn’t my modal close?

Asked

Viewed 830 times

1

Why doesn’t my modal close?

I couldn’t find anything wrong, especially when compared to other similar fashions that I have.

When I click the close button, it does not give the Ismiss, do not understand.

JS is added and I have other similar modals in my system, I don’t know what’s wrong with this.

Can someone help me?

    <!-- Modal -->
<div class="modal fade" id="adicionar" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Adicionar</h4>
            </div>

            <div class="modal-body">
                {{ Form::open(array('route' => array('tipos.store'), 'method' => 'POST')) }}
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label for="">Nome do tipo</label>
                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                            <input type="text" placeholder="Casa, Apartamento, Sobrado..." required name="nome" id="" class="form-control">
                        </div>
                    </div>
                </div>

                <hr>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <button type="submit" class="btn btn-success waves-effect waves-light">Salvar</button>
                        </div>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
  • There seems to be nothing wrong with the modal. Run a test: run this code on the console $("#adicionar > div > div > div.modal-header > button").click(function(){alert("ok")}) ... then click on the X of the modal and see if the alert is fired.

  • You can ask the question the library used and how to open the modal, self or by clicking on an element?

1 answer

1

There are no errors in the code posted, but it would be necessary for you to put in your question the library used and the way you open the modal as examples below

1 - Auto

 $("#adicionar").modal('show');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- Modal -->
<div class="modal fade" id="adicionar" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Adicionar</h4>
            </div>

            <div class="modal-body">
                {{ Form::open(array('route' => array('tipos.store'), 'method' => 'POST')) }}
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label for="">Nome do tipo</label>
                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                            <input type="text" placeholder="Casa, Apartamento, Sobrado..." required name="nome" id="" class="form-control">
                        </div>
                    </div>
                </div>

                <hr>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <button type="submit" class="btn btn-success waves-effect waves-light">Salvar</button>
                        </div>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>

2- Click on button

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#adicionar">Abrir Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="adicionar" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Adicionar</h4>
            </div>

            <div class="modal-body">
                {{ Form::open(array('route' => array('tipos.store'), 'method' => 'POST')) }}
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label for="">Nome do tipo</label>
                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                            <input type="text" placeholder="Casa, Apartamento, Sobrado..." required name="nome" id="" class="form-control">
                        </div>
                    </div>
                </div>

                <hr>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <button type="submit" class="btn btn-success waves-effect waves-light">Salvar</button>
                        </div>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.