Проверьте значение с помощью флажка - PullRequest
0 голосов
/ 13 сентября 2018

Проблема заключается в том, что я не могу позволить установить флажок, если номер atendimento (atendimento.value) отличается от ранее введенного номера. Когда я впервые нажимаю на 1 флажок, я сохраняю это значение и отправляю в массив.

Если я нажму на другой флажок и значение atendimento.value будет другим, будет отображено сообщение об ошибке с тостом.

Я хотел бы знать, что я забыл / пропустил в своем коде.

ng.checkAtendimento = function(id) {

    var atendimento = document.getElementById('atendimento-' + id);
    var checkOs = document.getElementById('checkOs-' + id);
    var array = [];

    if(checkOs.checked){
        array.push(atendimento.value);
        console.log(array);
    }else{  
        var index = array.indexOf(atendimento.value);
        array.splice(index, 1); 
        console.log(array);
    }

    if(array[0] != atendimento.value){
        console.log(array[0]);
            toastr.error(
                        'error',
                        'service', {
                        closeButton: true,
                        progressBar: true,
                        timeOut: 7000
                });
        checkOs.checked = false;
    }
}

HTML / PHP

<input id="checkOs-<?php echo $entity->getId(); ?>" 
       ng-click="checkAtendimento('<?php echo $entity->getId(); ?>');" 
       type="checkbox" 
       class="array-ordemservico" 
       name="[]array-ordemservico" 
       value="<?php echo $entity->getId();?>" />

<input id="atendimento-<?php echo $entity->getId(); ?>" 
       class="array-atendimento" 
       style="display:none" type="checkbox" 
       value="<?php echo $entity->getAtendimento(); ?>" />

1 Ответ

0 голосов
/ 25 сентября 2018
ng.checkAtendimento = function(id){
var atendimento = document.getElementById('atendimento-' + id);
$("#checkOs-" + id).on("change", function (){
index = $.inArray(atendimento.value, ArrayCheckbox);
if ($("#checkOs-" + id).prop('checked')){
   if (ArrayCheckbox.length > 0 && index === -1 && atendimento.value != ""){
        toastr.error(
                        'error',
                        'OS',{
                        closeButton: true,
                        progressBar: true,
                        timeOut: 7000
        });
        $("#checkOs-" + id).prop("checked", false); 
    } else if(ArrayCheckbox.length == 0 && atendimento.value != ""){
        ArrayCheckbox.push(atendimento.value);
        }
    } else if((ArrayCheckbox[0] == atendimento.value)){
        ArrayCheckbox.splice(index, 1);
    }

}); }

...