Ẩn nút thêm người dùng khi chưa tìm kiếm kiểm tra

trong sale.js  cần chỉnh 2 thêm vào

document.getElementById("customers-add").style.display = 'none';

document.getElementById("customers-add").style.display = 'block';

 

chỗ :

function nsCustomer() {
    $('#slcustomer').select2({
        minimumInputLength: 1,
        ajax: {
            url: site.base_url + "customers/suggestions",
            dataType: 'json',
            quietMillis: 15,
            data: function (term, page) {
                return {
                    term: term,
                    limit: 10
                };
            },
            results: function (data, page) {
                if (data.results != null) {
          
          document.getElementById("customers-add").style.display = 'none';
                    return {results: data.results};
                } else {
          document.getElementById("customers-add").style.display = 'block';
                    return {results: [{id: '', text: 'No Match Found'}]};
                }
            }
        }
    });
}

if (slcustomer = localStorage.getItem('slcustomer')) {
        $customer.val(slcustomer).select2({
            minimumInputLength: 1,
            data: [],
            initSelection: function (element, callback) {
                $.ajax({
                    type: "get", async: false,
                    url: site.base_url+"customers/getCustomer/" + $(element).val(),
                    dataType: "json",
                    success: function (data) {
                        callback(data[0]);
                    }
                });
            },
            ajax: {
                url: site.base_url + "customers/suggestions",
                dataType: 'json',
                quietMillis: 15,
                data: function (term, page) {
                    return {
                        term: term,
                        limit: 10
                    };
                },
                results: function (data, page) {
                    if (data.results != null) {
            document.getElementById("customers-add").style.display = 'none';
                        return {results: data.results};
                    } else {
            document.getElementById("customers-add").style.display = 'block';
                        return {results: [{id: '', text: 'No Match Found'}]};
                    }
                }
            }
        });
    } else {
        nsCustomer();
    }

Trong views sales/add.php :

<?php if ($Owner || $Admin || $GP['customers-add']) { ?>
                        <div class="fprom-group col-md-12" id="customers-add" style="    padding: 0;display:none">
                           <a href="<?= admin_url('customers/add'); ?>" id="add-customer"class="external" data-toggle="modal" data-target="#myModal">
                                                     <button type="button" class="btn btn-danger" style="width: 100%;">THÊM NGƯỜI DÙNG</button>
                          </a>
                          </div>
                      <?php } ?>

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*