как показать разные модальности начальной загрузки на одной странице - PullRequest
0 голосов
/ 29 сентября 2019

Я пытаюсь открыть несколько модалов на одной странице, но их идентификаторы конфликтуют друг с другом.Я получил этот код из документации по bootstrap-4,

Модал 1 работает нормально, но модал 2 не работает, я хочу, чтобы они оба работали отдельно

код:

modal1

  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
                  Add New
                </button>

  <!-- Modal Add Owner -->
  <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Owner</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" action="{{ route('owner.store') }}">
        @csrf
          <div class="form-group">
            <label for="">Add Owner Name</label>
            <input type="text" name="owner_name" class="form-control" id="" placeholder="Owner Name">
          </div>
          <input type="submit" name="submit" class="btn btn-primary" value="submit">
        </form>  
      </div>
        <div class="modal-footer">
        </div>
      </div>
    </div>
  </div>

modal2:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                      <a href="{{ route('owner.show', $owner->id)}}" class="btn btn-primary" data-toggle="modalshow" data-target="#exampleModalshow">Show</a>
                    </button>


  <!-- Modal Show Owner-->
  <div class="modal fade" id="exampleModalshow" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabe2" aria-hidden="true">
   <div class="modal-dialog" role="document">
     <div class="modal-content">
       <div class="modal-header">
         <h5 class="modal-title" id="exampleModalLabel">View Owner</h5>
         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" action="{{ route('owner.update', $owner->id) }}">
        @csrf
        @method('PATCH')
          <div class="form-group">
            <label for="">Owner Name</label>
            <input type="text" name="owner_name" class="form-control" value="{{ $owner->owner_name }}">
          </div>
          <input type="submit" name="submit" class="btn btn-primary" value="submit">
        </form>  
      </div>
      <div class="modal-footer">
      </div>
    </div>
  </div>
 </div>

1 Ответ

1 голос
/ 29 сентября 2019

Измените data-target на второй модальной кнопке, чтобы соответствовать модальному идентификатору

<button data-target="#exampleModalshow">
   ... rest of the code
</button>
...