1

This is the modal:

<div class="modal fade" id="modalInsertAgression" tabindex="-1" role="dialog" aria-labelledby="modalInsertAgression" aria-hidden="true">
<div class="modal-dialog" role="document">
    <div class="card">

        <form id="formInsertarAgresion" action="{% url 'insertarAgresion' %}" role="form">{% csrf_token %}
            <div class="card-header card-header-icon" data-background-color="rose">
                <i class="material-icons">place</i>
            </div>

            <div class="card-content">
                <h4 class="card-title">Test</h4>
                <p class="text-center" id="msgModalInsertAgression"></p>
                <br>

                <div class="input-group">
                    <span class="input-group-addon"><i class="material-icons">date_range</i></span>
                    <div class="form-group">{{ agresionForm.fecha }}</div>
                </div>
            </div>

            <div class="card-footer pull-right">
                <button id="btnInsertModalInsertAgression" type="submit" class="btn btn-fill btn-rose">Insertar</button>
                <button id="btnCloseModalInsertAgression" type="button" class="btn btn-default btn-fill" data-dismiss="modal">Cancelar</button>
            </div>
        </form>

    </div>
</div>

I open it with:

$("#modalInsertAgression").show();

It does not work on iPhone, when the modal appears the background keeps black and it lost the focus, you can not click in the modal or the buttons.

Edit: The modal only works with $("#modalInsertAgression").modal({backdrop: false}); but I do not want to lose the black background...

Jota
  • 697
  • 10
  • 24

2 Answers2

0

Try with (tested on iOS 11):

$('#modalInsertAgression').modal('show');

Snippet:

$('#modalInsertAgression').modal('show');
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="modalInsertAgression" tabindex="-1" role="dialog" aria-labelledby="modalInsertAgression" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="card">
      <form id="formInsertarAgresion" action="{% url 'insertarAgresion' %}" role="form">{% csrf_token %}
        <div class="card-header card-header-icon" data-background-color="rose">
          <i class="material-icons">place</i>
        </div>
        <div class="card-content">
          <h4 class="card-title">Test</h4>
          <p class="text-center" id="msgModalInsertAgression"></p>
          <br>
          <div class="input-group">
            <span class="input-group-addon"><i class="material-icons">date_range</i></span>
            <div class="form-group">{{ agresionForm.fecha }}</div>
          </div>
        </div>
        <div class="card-footer pull-right">
          <button id="btnInsertModalInsertAgression" type="submit" class="btn btn-fill btn-rose">Insertar</button>
          <button id="btnCloseModalInsertAgression" type="button" class="btn btn-default btn-fill" data-dismiss="modal">Cancelar</button>
        </div>
      </form>
    </div>
  </div>
Syden
  • 8,425
  • 5
  • 26
  • 45
  • It does not work for me on iPhone 6 iOS 11.2.6 Only works with `$("#modalInsertAgression").modal({backdrop: false});` but it loses the black background... – Jota Mar 21 '18 at 15:38
  • Which bootstrap version is it? Are you able to create a working fiddle at least for desktop, because it wasn't the case with the shared code. By the way, with the backdrop approach you are removing indeed the black background. – Syden Mar 21 '18 at 15:41
  • It is bootstrap 3.3.7 – Jota Mar 21 '18 at 18:01
  • Jota, in that case you have a working example above with the code fragment you've shared, if you still can't fix it, maybe share more code or a url? – Syden Mar 21 '18 at 18:10
0

I found the solution here:

If the modal container has a fixed or relative position or is within an element with fixed or relative position this behavior will occur. Bootstrap modal appearing under background

Jota
  • 697
  • 10
  • 24