1

Bloodhound's prefetch feature is working great for me, but I would like to disable my inputs while the prefetch is happening.

Does anyone know of a way to detect when the prefetch is happening, do something, and then do something else when the prefetch is complete? Here is my code.

// Nav typeahead
var costCenters = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),        
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: dsg_site_root + 'autocomplete/costCenterPullDownNamesComplete'
})

var employees = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: dsg_site_root + 'autocomplete/employeePullDownNamesComplete'
})

$(function() {    
    $('#navSearch').typeahead({
        highlight: true,
        maxItem: 20,
    },
    {
        name: 'costCenters',   
        display: 'display',   
        source: costCenters,
        templates: {
            header: '<h6 class="ml-3 mt-2 text-secondary">Cost Centers</h6>'
        }
    },
    {
        name: 'employees',  
        display: 'display',      
        source: employees,
        templates: {
            header: '<h6 class="ml-3 mt-2 text-secondary">Employees</h6>'
        }
    })

    $('#navSearch').bind('typeahead:select', function(ev, chosen) { 
        if(chosen.category == 'employees') {
            window.location.href = dsg_site_root + 'employee/index/' + chosen.id                
        } else {
            window.location.href = dsg_site_root + 'costCenter/index/' + chosen.id      
        }                               
    })         
})

Thanks in advance.

Ryan.Jones
  • 31
  • 6

0 Answers0