How to “unbind” .result on Jquery Autocomplete?

Posted by Cesar on Stack Overflow See other posts from Stack Overflow or by Cesar
Published on 2010-03-17T13:04:04Z Indexed on 2010/03/17 13:41 UTC
Read the original article Hit count: 454

Filed under:
|
|
|

I have this code:

$("#xyz").unautocomplete().autocomplete(dataVar, {
    minChars: 0,
    width: 400,
    matchContains: true,
    highlightItem: true,
    formatItem: formatItem,
    formatResult: formatResult
})
.result(findValueCallback).next().click(function() {
    $(this).prev().search();
});

I call this code many times and the first call works correctly, but after he calls findValueCallback many times, not once more.

The unautocomplete don't clear .result

What I have to do for call findValueCallback once?

Sample Code:

var niveis01 = [];
var niveis02 = [];
var niveis03 = [];

$(document).ready(function(){
    carregaDadosNivel1();
});

function carregaDadosNivel1() {
    $.ajax({
        url: "http://.....",
        cache: true,
        type: "POST",
        dataType:"json",
        success: function(data){
            ...
            niveis01 = data;
            habilitaComboNivel1();
            ...
        },
        error: function(xhr, ajaxOptions, thrownError){
            ...
        }
    });
}

function habilitaComboNivel1() {
    function findValueCallback1(event, data01, formatted) {
        ...
        carregaDadosNivel2();
        ...
    }

    $("#nivel01").unautocomplete().autocomplete(niveis01, {
        minChars: 0,
        width: 400,
        matchContains: true,
        highlightItem: true,
        formatItem: formatItem,
        formatResult: formatResult
    }).result(findValueCallback1).next().click(function() {
        $(this).prev().search();
    });
}

function carregaDadosNivel2() {
    $.ajax({
        url: "http://.....",
        cache: true,
        type: "POST",
        dataType:"json",
        success: function(data){
            ...
            niveis02 = data;
            habilitaComboNivel2();
            ...
        },
        error: function(xhr, ajaxOptions, thrownError){
            ...
        }
    });
}

function habilitaComboNivel2() {
    function findValueCallback2(event, data02, formatted) {
        ...
        carregaDadosNivel3();
        ...
    }

    $("#nivel02").unautocomplete().autocomplete(niveis02, {
        minChars: 0,
        width: 400,
        matchContains: true,
        highlightItem: true,
        formatItem: formatItem,
        formatResult: formatResult
    }).result(findValueCallback2).next().click(function() {
        $(this).prev().search();
    });
}

function carregaDadosNivel3() {
    $.ajax({
        url: ""http://.....",
        cache: true,
        type: "POST",
        dataType:"json",
        success: function(data){
            ...
            niveis03 = data;
            habilitaComboNivel3();
            ...
        },
        error: function(xhr, ajaxOptions, thrownError){
            ...
        }
    });
}

function habilitaComboNivel3() {
    function findValueCallback3(event, data03, formatted) {
        ...
    }

    $("#nivel03").unautocomplete().autocomplete(niveis03, {
        minChars: 0,
        width: 400,
        matchContains: true,
        highlightItem: true,
        formatItem: formatItem,
        formatResult: formatResult
    }).result(findValueCallback3).next().click(function() {
        $(this).prev().search();
    });
}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about autocomplete