Leave the corresponding checkboxes marked

0

Good morning I have a list of candidates that can be associated to a certain vacancy, from the checkbox I validate that if that selected candidate is already associated, send a modal with that message and therefore if you select another one that does not send nothing. So all right only that I put a sentence in which to leave that modal uncheck the checkbox but it does even with the vacancy that has no link, that is, if I select a candidate who is not associated does not send the modal or remove the popcorn from the checkbox (it's fine) and if I choose another one, if it is, send the modal (it's ok) but uncheck me until the other checkbox of the candidate who is not associated. How can you make it to only remove the selection of the candidate who is already associated and leave the others who do not? I believe that it must be in a property only that I do not know what it is. And if it's something else this is the code:

$('#formDatosCandidatos').on('change','input[class="idRecurso"]',function(){
     var buttons = "";
     var table = $('#tabla').DataTable();

     buttons = table.buttons( ['.asociarVacante'] );

     var idRecurso = $(this).val();

     var idVacantes = <?= json_encode($idV,JSON_HEX_QUOT | 
                      JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS
                     ) ?>

     $.ajax({
        url: ajaxVerificaVacante2,
        type: 'post',
        data: {
          idRecurso : idRecurso,
          idVacantes  : idVacantes,
          _csrf  : _csrfToken
        },
        success: function(data){
          console.log(data);
          if(data.mensajes != 0){
            var Contenido ='';

            $("#texto").html(data.mensajes);

            $(".idRecurso").prop('checked', false); //AQUI ES DONDE DESHABILITO EL CHECKBOX PERO ENTIENDE QUE DESMARQUE TODOS SI SELECCIONA UNO QUE ESTE ASOCIADO

            buttons.disable();
            $('#existeEnVacante').modal('show');
          }
        },
        error: function(exception){
          console.log('error' + exception);
        }
      });

    if(this.checked==true){
        buttons.enable();
    } else {
        buttons.disable();

    }
});
    
asked by Ivan92 11.12.2017 в 17:59
source

1 answer

0

It's been a while since I was able to solve it ... it happened to me to publish it in case it is taken care of, the fragment that enters this commented:

$('#formDatosCandidatos').on('change','input[class="idRecurso"]',function(){
     var buttons = "";
     var table = $('#tabla').DataTable();

     buttons = table.buttons( ['.asociarVacante'] );

     var idRecurso = $(this).val();

     var idVacantes = <?= json_encode($idV,JSON_HEX_QUOT | 
                      JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS
                     ) ?>

     $.ajax({
        url: ajaxVerificaVacante2,
        type: 'post',
        data: {
          idRecurso : idRecurso,
          idVacantes  : idVacantes,
          _csrf  : _csrfToken
        },
        success: function(data){
          console.log(data);
          if(data.mensajes != 0){
            var Contenido ='';

            $("#texto").html(data.mensajes);
            $('#existeEnVacante').modal('show');

            //Recorrer los checkbox y dependiendo lo que
            //tenga el indice (e), si es igual al correspondiente
            //id del candidato asociado a la vacante, marca
            //o desmarca el checkbox dejando los otros
            $('#formDatosCandidatos input[type=checkbox]').each(function(i,e){

              if($(e).val()==idRecurso){
                $(e).prop('checked',false);
                buttons.disable();

                $('input[class="idRecurso"]:checked').each(function() {
                  buttons.enable();
                });
              }
            });
          }
        },
        error: function(exception){
          console.log('error' + exception);
        }
      });

    if(this.checked==true){
        buttons.enable();
    } else {
        buttons.disable();

        $('input[class="idRecurso"]:checked').each(function() {
          buttons.enable();
        });
    }
});
    
answered by 11.12.2017 / 22:51
source