Jquery UI autocomplete event change

后端 未结 2 665
眼角桃花
眼角桃花 2021-01-03 08:20

Hi I got a problem with change event. By documntation there should be object ui.item

After an item was selected; ui.item refers to the selected item.

2条回答
  •  借酒劲吻你
    2021-01-03 08:50

    I find out solution where I testing event.originalEvent.type if it is meneuselected or not and after fail I unset s_town_id. But any better solution is still wellcome.

    
    
    
    
        
     $(function() {
      $("#s_town").autocomplete({
       source: function(request, response) {
        $.ajax({
         url: "/_system/_ajax/uiautocomplete.php",
         dataType: "json",
         data: {
          name: "s_town",
          term: request.term
         },
         success: function(data) {
          response($.map(data, function(item) {
           return {
            label: item.whisper_name+ " [" + item.zip_code + " / " + item.lup_state + "]",
            value: item.whisper_name,
            id: item.whisper_id, 
            zip_code: item.zip_code, 
            lup_state: item.lup_state, 
            stateid: item.stateid
           }
          }))
         }
        })
       },
       minLength: 2,
       select: function(event, ui) {
        $("#s_town_id").val(ui.item.id);
       },
       change: function(event, ui)
       {
        try
        {
            if(event.originalEvent.type != "menuselected")
            {
                 // Unset ID
                 $("#s_town_id").val("");
            }
        }
        catch(err){ 
            // unset ID 
            $("#s_town_id").val("");
        }
       }
    
      });
    
    
     });
        
    
    
    

提交回复
热议问题