Pregunta

I have two typeahead input boxes.. Here's the code for both.

$('#input1').typeahead({
    name: 'DrugName',
    remote: {
        url: 'Model/Dataset1.js',
        filter: function (parsedResponse) {
            // do whatever processing you need here
            return parsedResponse;
        }
    },
    valueKey: "DrugName",
    template: [
        '<div class="typeahead-dropdown">',
        '<p class="tt-drugname">{{DrugName}}</p>',
        '</div>',
    ].join(''),
    engine: Hogan
});

second :

$('#input2').typeahead({
    name: 'Name',
    remote: {
        url: 'Model/Dataset2.js',
        filter: function (parsedResponse) {
            // do whatever processing you need here
            return parsedResponse;
        }
    },
    valueKey: "Name",
    template: [
        '<div class="typeahead-dropdown">',
        '<p class="tt-drugname">{{DrugName}}</p>',
        '</div>',
    ].join(''),
    engine: Hogan
});

First one is working fine but second one returns this error when I select the dropdown option.

Error: one of local, prefetch, or remote is required

I tried do have remote but I still get the error.. Nothing is wrong in code I believe. Can anyone help me out with the code?


Answer for this question

If you are getting error Error: one of local, prefetch, or remote is required even if you have provided local, prefetch or remote source.. The problem is not in JavaScript code..

I fixed it by editing the Input DOM element.

It was <input type="text" class="tw-typeahead" autofocus="autofocus" /> before. I changed it to <input type="text" class="tw-typeahead" />..

Removing autofocus property fixed all the errors.. Weird but this is the issue. I was fighting with the code for like 2 days but finally found it!..

Thanks,

Rahul Patil

¿Fue útil?

Solución

If you are getting error Error: one of local, prefetch, or remote is required even if you have provided local, prefetch or remote source.. The problem is not in JavaScript code..

I fixed it by editing the Input DOM element.

It was <input type="text" class="tw-typeahead" autofocus="autofocus" /> before. I changed it to <input type="text" class="tw-typeahead" />..

Removing autofocus property fixed all the errors.. Weird but this is the issue. I was fighting with the code for like 2 days but finally found it!..

Thanks,

Rahul Patil

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top