【问题标题】:Select multiple accumulates data, how to clean it?选择多个累积数据,如何清理?
【发布时间】:2016-01-10 07:26:13
【问题描述】:

帮助,我有一个表格,当我选择客户时会自动填充数据,其中包括他们的地址,地址被加载到多个选择中。问题是这样的:当我选择另一个客户时,表格没有完全清理,要么以前客户的地址作为当前客户的地址,要么在选择多个中累积。选择另一个客户时是否可以自动清理整个表单或至少选择多个?谢谢。

$('input[name=\'customer\']').catcomplete({
 minLength: 0, delay: 100,
source: function(request, response) {
    $.ajax({
        url: 'index.php?route=sale/customer/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
        dataType: 'json',
        success: function(json) {   
            response($.map(json, function(item) {
                return {
                    category: item['customer_group'],
                    label: item['name'],
                    value: item['customer_id'],
                    customer_group_id: item['customer_group_id'],
                    firstname: item['firstname'],
                    lastname: item['lastname'],
                    rut_cliente_id: item['rut_cliente_id'],
                    email: item['email'],
                    telephone: item['telephone'],
                    fax: item['fax'],
                    banca: item['banca'],
                    company: item['company'],
                    iban: item['iban'],
                    address: item['address']
                }
            }));
        }
    });
}, 

select:function(event,ui){
    event.preventDefault()
    $('input[name=\'customer\']').val(ui.item.label);
    $('input[name=\'customer_id\']').val(ui.item.value);
    $('input[name=\'firstname\']').val(ui.item.firstname);
    $('input[name=\'lastname\']').val(ui.item.lastname);
    $('input[name=\'rut_cliente_id\']').val(ui.item.rut_cliente_id);
    $('input[name=\'email\']').val(ui.item.email);
    $('input[name=\'telephone\']').val(ui.item.telephone);
    $('input[name=\'banca\']').val(ui.item.banca);
    $('input[name=\'iban\']').val(ui.item.iban);
    $('input[name=\'company\']').val(ui.item.company);
    $('input[name=\'fax\']').val(ui.item.fax);




    for(i in ui.item.address){ 

        html+='<option value="' + ui.item.address[i]['address_id']+'">'+ui.item.address[i]['firstname']+' ' + ui.item.address[i]['lastname']+', ' + ui.item.address[i]['address_1']+', ' + ui.item.address[i]['city']+', ' + ui.item.address[i]['country']+'</option>';
    }

    $('select[name=\'shipping_address\']').html(html);
    $('select[name=\'payment_address\']').html(html);

    $('select[id=\'customer_group_id\']').removeAttr('disabled').val(ui.item['customer_group_id']).change().attr('disabled',true); 


    return false; 

}});

【问题讨论】:

    标签: javascript jquery json ajax forms


    【解决方案1】:

    在设置新值之前使用此代码

    $("input").each(function(){
       $(this).val("");
    });
    $('select[name=\'shipping_address\']').html("");
    $('select[name=\'payment_address\']').html("");
    html = ""
    

    【讨论】:

      猜你喜欢
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      相关资源
      最近更新 更多