Have typeahead.js output into multiple text boxes

前端 未结 3 1086
死守一世寂寞
死守一世寂寞 2021-01-03 12:33

I\'m working on an internal web form for my company I was trying to use typehead.js to load a name from a local array. I was able to do this without a problem, however the s

3条回答
  •  清酒与你
    2021-01-03 13:16

    I've implemented the functionality you are looking for here:

    http://jsfiddle.net/Fresh/kLLCy/

    The trick to populating the ID field when the name is selected is as follows:

    var employeeNameItemSelectedHandler = 
     function (eventObject, suggestionObject, suggestionDataset) {
        // The following should work but it has an issue
        //employeeIdTypeahead.typeahead('val', suggestionObject.id);
        employeeIdTypeahead.val(suggestionObject.id);
    };
    
    employeeNameTypeahead.on('typeahead:selected', employeeNameItemSelectedHandler);
    

    Note that whilst:

    employeeIdTypeahead.typeahead('val', suggestionObject.id);
    

    does work, the problem is that it causes the suggestion to be displayed when the employee Id Typeahead input is populated (and vice versa), which I think maybe an issue (this behaviour is not mentioned in the typeahead documentation. Hence why I've used ".val()" to populate the input.

提交回复
热议问题