vendredi 17 février 2017

Laravel Bootstrap Modal Not Displaying

So I've created a seperate blade (form.blade.php) that has all the form model binding code and an index blade that has the main content and a delete modal that can be manipulated through the controller and with ajax. My main problem is that the modal itself is not displaying. I'm using bootstrap 3.3.7.

Jquery Ajax syntax to display modal:

  $('.add_modal').on('click', function(e) {
  e.preventDefault();
  $('#modal').removeClass('modal-warning modal-primary');
  $('#modal').addClass('modal-success');

  console.log('open_add_modal');

  $.ajax({
    type: 'GET',
    url: '',
    success: function(data) {
      $('#modal-dialog').text('');
      $('#modal-dialog').append(data);
      $('#modal').modal('show');
    }
  });
});

Here's the line of code that's supposed to trigger the said modal:

<a href="#" class="btn btn-success btn-block add_modal" style="border-radius: 0px"><i class="fa fa-plus-square"></i> Add Personnel</a>

My controller code for 'create':

public function create(Request $request) {
 if($request->ajax()) {
    $title = "Add New Personnel";
    return view('wagon.maintenance.personnel.form')
        ->with('title', $title)
        ->with('button_text', "Add")
        ->with('type', "CREATE")
        ->with('action', "btn-success add");
 }
 else {
    return redirect(route('personnel.index'));
 }
}

And finally my form binding syntax:

<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"></h4>
</div>

@if($type=="CREATE")
    {!! Form::open(array ('id'=>'add_form', 'class'=>'form-horizontal', 'route'=>'personnel.store') ) !!}
@elseif($type=="EDIT")
    {!! Form::model($personnel, array ('id'=>'edit_form', 'class'=>'form-horizontal', 'route'=>array('personnel.update', '$personnel->strPersonnelID'), 'method'=>'PUT') ) !!}
@else
    {!! Form::model($personnel, array ('id'=>'view_form', 'class'=>'form-horizontal', 'route'=>'personnel.index' )) !!}
@endif



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire