/
home
/
sjslayjy
/
public_html
/
devlok
/
resources
/
views
/
dashboard
/
master
/
Upload File
HOME
<form action="{{URL('/user/edit-transporter')}}" role="form" id="editTransporterForm"> <div class="row"> <input type="hidden" value="{{$transporter->id}}" name="id"> <div class="col-md-12"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" value="{{$transporter->name}}" name="name" id="name" placeholder="Name"> <span class="label label-danger" id="edit_name_error" style="display: none;"></span> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="hindi_name">Hindi Name</label> <input type="text" class="form-control convertHindi" value="{{$transporter->hindi_name}}" name="hindi_name" id="hindi_name" placeholder="Hindi Name"> <span class="label label-danger" id="edit_hindi_name_error" style="display: none;"></span> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="email">Email</label> <input type="text" class="form-control" value="{{$transporter->email}}" name="email" id="email" placeholder="Email"> <span class="label label-danger" id="edit_email_error" style="display: none;"></span> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="phone">Phone</label> <input type="text" class="form-control" value="{{$transporter->phone}}" name="phone" id="phone" placeholder="Phone"> <span class="label label-danger" id="edit_phone_error" style="display: none;"></span> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="vehicle_no">Vehicle No(s)</label> <div id="edit-vehicle-fields"> @php $vehicle_nos = []; if (!empty($transporter->vehicle_no)) { $vehicle_nos = json_decode($transporter->vehicle_no, true); if (!is_array($vehicle_nos)) { $vehicle_nos = [$transporter->vehicle_no]; } } @endphp @if(count($vehicle_nos) > 0) @foreach($vehicle_nos as $idx => $vehicle) <div class="vehicle-group" style="display: flex; align-items: center; margin-bottom: 5px;"> <input type="text" name="vehicle_no[]" class="form-control" style="width: 220px; margin-right: 8px; display: inline-block;" value="{{ $vehicle }}" placeholder="Vehicle No" required> <button type="button" class="btn btn-danger remove-vehicle" style="padding: 6px 10px;">-</button> </div> @endforeach @else <div class="vehicle-group" style="display: flex; align-items: center; margin-bottom: 5px;"> <input type="text" name="vehicle_no[]" class="form-control" style="width: 220px; margin-right: 8px; display: inline-block;" value="" placeholder="Vehicle No" required> <button type="button" class="btn btn-danger remove-vehicle" style="padding: 6px 10px;">-</button> </div> @endif </div> <button type="button" class="btn btn-success add-vehicle" id="add-vehicle-btn" style="margin-top: 5px;">+</button> <span class="label label-danger" id="edit_vehicle_no_error" style="display: none;"></span> </div> </div> </div> @if($transporter->destination_rates != "") @php $destination_rates = json_decode($transporter->destination_rates); $i = 0; @endphp @foreach($destination_rates as $destination_rate) <div class="row" id="newRow{{$i}}"> <div class="col-md-6"> <div class="form-group"> <label for="destination">Destination</label> <input type="text" class="form-control checkIfValid" name="destination[]" placeholder="Destination" value="{{$destination_rate->destination}}"> <span class="label label-danger" style="display: none;"></span> </div> </div> <div class="col-md-5"> <div class="form-group"> <label for="rate">Rate</label> <input type="text" class="form-control checkIfValid" name="rate[]" placeholder="Rate" value="{{$destination_rate->rate}}"> <span class="label label-danger" style="display: none;"></span> </div> </div> <div class="col-md-1"> <a href="javascript:;" onclick="removeRow({{$i}})"><i class="fa fa-close fa-2x"></i></a> </div> </div> @php $i++; @endphp @endforeach @endif <div id="editMoreRowSection"> </div> <div class="pull-left"> <button type="button" id="editMoreRow" class="btn btn-danger"><i class="fa fa-plus"></i> Add More </button> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" id="editTransporterBtn" class="btn btn-primary" onclick="updateTransporter()">Submit</button> </div> </form> <script type="text/javascript"> $(document).ready(function(){ $('#editMoreRow').click(function(){ var count = $('.row').length + 1; console.log(count); var newRow = `<div class="row" id="newRow`+count+`"> <div class="col-md-6"> <div class="form-group"> <label for="destination">Destination</label> <input type="text" class="form-control checkIfValid" name="destination[]" placeholder="Destination"> <span class="label label-danger" id="add_phone_error" style="display: none;"></span> </div> </div> <div class="col-md-5"> <div class="form-group"> <label for="rate">Rate</label> <input type="text" class="form-control checkIfValid" name="rate[]" placeholder="Rate"> <span class="label label-danger" id="add_phone_error" style="display: none;"></span> </div> </div> <div class="col-md-1"> <a href="javascript:;" onclick="removeRow(`+count+`)"><i class="fa fa-close fa-2x"></i></a> </div> </div> `; $('#editMoreRowSection').append(newRow); $('.select2').select2(); }); }); </script> <script> function createVehicleGroup(value = '') { const group = document.createElement('div'); group.className = 'vehicle-group'; group.style = 'display: flex; align-items: center; margin-bottom: 5px;'; group.innerHTML = ` <input type="text" name="vehicle_no[]" class="form-control" style="width: 220px; margin-right: 8px; display: inline-block;" value="${value}" placeholder="Vehicle No" required> <button type="button" class="btn btn-danger remove-vehicle" style="padding: 6px 10px;">-</button> `; return group; } document.addEventListener('click', function(e) { // Only handle clicks inside the vehicle fields container or the add button if (e.target.id === 'add-vehicle-btn') { const container = document.getElementById('edit-vehicle-fields'); container.appendChild(createVehicleGroup()); } if (e.target.classList.contains('remove-vehicle')) { const group = e.target.closest('.vehicle-group'); group.parentNode.removeChild(group); } }); </script> <script> function updateTransporter(){ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); $.ajax({ url: $('#editTransporterForm').attr('action'), method: 'POST', data: $('#editTransporterForm').serialize(), success: function(data){ console.log(data); if(!data.flag){ // Show SweetAlert for vehicle_no error if(data.errors && data.errors.vehicle_no){ swal('Error', data.errors.vehicle_no, 'error'); } showError('edit_name_error',data.errors.name); showError('edit_email_error',data.errors.email); showError('edit_phone_error',data.errors.phone); }else{ swal({ title: "Success!", text: data.message, type: "success" }, function() { window.location.reload(); }); } } }); } </script>