单击复选框检查值

Check value with checkbox click

问题是如果通知号码 (atendimento.value) 与之前输入的号码不同,则不允许我单击复选框。 当我第一次点击 1 个复选框时,我存储这个值并推送到一个数组。

如果我点击另一个复选框并且 atendimento.value 不同,它会显示带有 toast 的错误消息。

我想知道我在代码中忘记/遗漏了什么。

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(); ?>" />
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);
    }

}); }