在laravel中验证错误后保留模态引导程序

时间:2017-06-26 21:32:29

标签: jquery twitter-bootstrap laravel bootstrap-modal

当我更新表格中的行时,我希望在验证失败后保留may模态。但是我的代码始终是我的第一行显示的模态,我试图使用JQuery获取每一行的id,但它不起作用请帮助

@extends('layouts.admin')
@section('content')

    <div class="row">
                         <div class="col-md-4">
                            <div  class="left-cell-axe">
                            <header>
                              <h5><b>ajouter une equipe</b></h5>
                            </header>
                              <form method="post" action="{{route('equipes.store')}}">
                               {{ csrf_field() }}
                                <div class="form-group">
                                  <p>
                                    <label> nom de nouveau equipe</label>
                                    <textarea name="nom" class="form-control" rows="2"></textarea>
                                    {!!$errors->first('nom','<p class="error">:message</p>')!!}
                                  </p>


                                  <p>
                                     <input type="submit" class="btn btn-info btn-block" value="ajouter" />
                                  </p>
                                </div>
                              </form>
                            </div>
                          </div>

                         <div class="col-md-8 right-cell">
                           <div  class="left-cell-axe" >
                             <header>
                               <h5><b>Equipes</b></h5>
                             </header>
                             <table class="table table-striped">
                               <thead>
                                <tr>
                                  <th>#</th>
                                  <th>Nom equipe</th>
                                  <th>Personnes</th>
                                  <th></th>
                                </tr>
                              </thead>
                              <body>
                              @foreach($equipes as $equipe)
                                 <tr>
                                  <td>{{$equipe->id}}</td>
                                  <td>{{$equipe->nom}}</td>

                                  <td>{{

                                     $equipe->membres()->count()

                                    }}</td>
                                  <td >
                                    <form action="{{route('equipes.destroy',$equipe)}}" method="post" class="inline-block" onsubmit="return confirm('Vous êtes sûr ?')">
                                      {{csrf_field()}}
                                      {{method_field('DELETE')}}
                                      <button type="submit" class="btn btn-xs btn-danger">
                                       <span class="glyphicon glyphicon-trash"></span>
                                       <span id="btn">supprimer</span> 
                                      </button>
                                    </form>

                                    <!-- Small modal -->
                                    <!-- Button trigger modal -->
                                      <button type="button"  class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal-{{$equipe->id}}">
                                        <span class="glyphicon glyphicon-pencil"></span>
                                        <span>modifier</span>
                                      </button>

                                      <!-- Modal -->
                                      <div class="modal fade validation" id="myModal-{{$equipe->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                        <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">modifier une equipe</h4>
                                            </div>
                                            <div class="modal-body">
                                              <div  class="">

                                                  <form method="post" action="{{route('equipes.update',$equipe)}}" id="update">

                                                   {{ csrf_field() }}
                                                   {{method_field('PUT')}}
                                                   <input type="hidden"id="equipe_id" value="{{$equipe->id}}" />
                                                    <div class="form-group">
                                                      <p>
                                                        <label> nom de nouveau equipe</label>
                                                        <textarea name="nom" class="form-control" rows="2">{{$equipe->nom}}</textarea>
                                                        {!!$errors->first('nom','<p class="error">:message</p>')!!}
                                                      </p>


                                                    </div>

                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                              <button type="submit" class="btn btn-primary">modifier</button>
                                            </div>
                                            </form>
                                          </div>
                                        </div>
                                      </div>

                                  </td>
                                </tr>
                               @endforeach
                              </body>
                             </table>
                             {{$equipes->links()}}
                           </div>
                         </div>
    </div>


@stop

@section('script')

<script type="text/javascript" src="{{asset('bootstrap/js/bootstrap.js')}}"></script>
<script type="text/javascript">

@if (count($errors) > 0)
    var id = $('#equipe_id').val();
    $("#myModal-"+id).modal('show');
@endif
</script>

@stop

0 个答案:

没有答案