1 operation: Through a select->option I load information to a div which will contain a form and within said form a table with a general checkbox that controls whether all the checkboxes of the table have to be marked or not and then has a checkbox per face row along with info.
2 The problem: when editing, I correctly fill in the select->option but I can't get the corresponding checkboxes to be marked, in fact I can't get any checkbox to be marked.
I have removed certain functions that did not paint much like the ajax that sent the data to the server
vista Blade
<div class="container col">
<div class="card subCabeceraModal">
<div class="row">
<div class="col">
<select class="form-control" id="clienteFusion">
<option value="">Selecciona un Cliente</option>
@foreach ($clientes as $var)
<option value="{{ $var->idCliente }}">{{ Str::length($var->cliente) >30? Str::substr($var->cliente, 0, 30).'....':$var->cliente}}</option>
@endforeach
</select>
</div>
</div>
<div class="row">
<div class="col" id="engancheOfertas">
<div id="tablaOfertas" style="height: 700px">
@if($ventas!='')
<div class="table-responsive" style="height: 500px">
<form id="fusionOfertasForm" name="fusionOfertasForm">
@csrf
<table class="table tablaPersonalizada table-bordered table-striped mb-0" style="overflow-y:auto;">
<thead>
<tr>
<th scope="col" class="col-1 cabeceraTabla">
<input type="checkbox" id="selectAllFusionOferta" name="selectAllFusionOferta">
</th>
<th scope="col" class="col-1 cabeceraTabla">ID</th>
<th scope="col" class="col-2 cabeceraTabla">FECHA</th>
<th scope="col" class="col-2 cabeceraTabla">TIPO</th>
<th scope="col"class="col-7 cabeceraTabla">OBSERVACIONES</th>
</tr>
</thead>
<tbody>
@foreach ($ventas as $venta)
<tr id="{{$venta->oferta->idOferta}}">
<td>
<input type="checkbox" class="selectFusionOferta" value="{{ $venta->oferta}}" name="selectFusionOferta[]">
</td>
<th scope="row">{{$venta->oferta->idOferta}} </th>
<td> {{ date("j-n-Y", strtotime($venta->oferta->fechaEnvioOfertaInicial))}} </td>
<td>{{$venta->tipo}}</td>
<td> {{$venta->oferta->observaciones}}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="col mt-3">
<button id="fusionOfertasFormBoton" type="button" class="btn btn-success">Fusión</button>
</div>
</form>
</div>
@endif
<script>
$(function(){
let validacion=0;
$('#clienteFusion').on('change', function(){
addInfoTabla($('#clienteFusion').val());
});
//selectores
$('#engancheOfertas').on('change', '#selectAllFusionOferta',function(){
$('input:checkbox').not(this).prop('checked', this.checked);
$('#fusionOfertasFormBoton').attr('disabled', false);
})
function editar(){
let editarCliente_id= <?php echo isset($editarCliente_id)?$editarCliente_id:0; ?> ;
let editarOfertas_id= <?php echo isset($editarOfertas_id)?json_encode($editarOfertas_id):0; ?>;
let ruta= "{{ $ruta ?? '' }}";
if (editarCliente_id!=0 && editarOfertas_id!=0 && ruta!='') {
console.log(editarOfertas_id);
//Cargo la informacion en los respectivos sitios
//select
$('#clienteFusion').val(editarCliente_id);
addInfoTabla($('#clienteFusion').val());
}
}
editar();
function addInfoTabla(cliente){
$.get('/ofertas-crear-grupos',{cliente: cliente } , function(respuesta){
$("#tablaOfertas").html( $(respuesta).find(' #tablaOfertas'));
validacion= $("#fusionOfertasForm").validate({debug: true,rules:{"selectFusionOferta[]":{required:true}}});
});
}
});
</script>
What you are trying to implement is wrong; According to the comments, as I was saying, if you are working with Laravel and you want to display elements within the table, you must use the resources to generate them
checkbox
from thephp
, and not through ajax or through a javascript script that the user selects in the query, when these elements can already come with the attributechecked
.The interesting thing about this aspect is that you are making 2 or 3 unnecessary requests when blade provides you with the tools you need to get the same result you expect.
You have to validate that you do not have syntax errors and that each variable step by step has what you expect in the possible scenarios.