mardi 13 novembre 2018

Laravel 5.6 update record from form in a model not submitting

I have a simple crud system that I build everything works fine except the UPDATE part.

When you try to edit a record a bootstrap modal pops up with a form in it with the records populated done with javascript. The action url for the form is also set by javascript. When I submit, the model simply closes, nothing happens.

Let's start with my resource route:

Route::resource('buildingimage', 'BuildingImageController');

The edit button:

<button
    class="edit-modal btn btn-info"
    data-buildingid=""
    data-location=""
    data-source=""
    data-disc=""
    data-result=""
    data-resultPositive=""
    data-resultNegative=""
    data-toggle="modal"
    data-target="#edit-building"
>
    <i class="far fa-edit"></i>
    Edit
</button>

I use all these data attributes to populate the edit form via javascript:

$('#edit-building').on('show.bs.modal', function(e) {
            let deleteUrl = 'buildingimage/' + $(e.relatedTarget).data('buildingid');
            $('#editBuilding').attr('action', deleteUrl);

            let location = $(e.relatedTarget).data('location');
            let source = $(e.relatedTarget).data('source');
            let disc = $(e.relatedTarget).data('disc');
            let result = $(e.relatedTarget).data('result');
            let resultPostitive =  $(e.relatedTarget).data('resultPostive');
            let resultNegative = $(e.relatedTarget).data('resultNegative');

            $('input[name=location]').val(location);
            $('input[name=source]').val(source);
            $('select[name=disc]').val(disc);
            $('select[name=result]').val(result);
    });

The form in my modal:


            <div class="form-group">
                <div class="row">
                    <div class="col-md-3 ">
                        
                        
                    </div>
                    <div class="col-md-2 noPaddingLeft">
                        

                    </div>
                    <div class="col-md-2 noPaddingLeft">
                        
                        
                    </div>
                    <div class="col-md-2 noPaddingLeft">
                        
                        
                    </div>
                    <div class="col-md-2 noPaddingLeft">
                        <div id="resultPositive">
                            
                            
                        </div>
                        <div id="resultNegative">
                            
                            
                        </div>
                    </div>
                    <div class="col-md-1 noPaddingLeft">
                        <br>
                        {!! Form::hidden('image_request_id', $imageRequest->id) !!}
                    </div>
                </div>
            </div>


Now I have no idea why the form is not submitting, literally nothing happens the modal just closes.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire