Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeahead remote not rendering all datums in suggestion list #442

Closed
jherax opened this issue Sep 11, 2013 · 3 comments
Closed

Typeahead remote not rendering all datums in suggestion list #442

jherax opened this issue Sep 11, 2013 · 3 comments

Comments

@jherax
Copy link

jherax commented Sep 11, 2013

This issue is too similar with Issue #416 - Issue #299

I used the "remote" property to set the datasource of suggestions.
The server returns a stringified json, so I used the "filter" function to parse the response:

[{
    id: 141501,
    nombre: 'ELSA MARIA JORDAN O ',
    email: 'irina.garzon@gmail.com',
    direccion: "DG 54 # 14 - 37"
},{
    id: 141501,
    nombre: 'ELSA MARIA JORDAN O ',
    email: 'irina.garzon@gmail.com',
    direccion: "dg"
},{
    id: 141560,
    nombre: 'LEONARDO ZAMBRANO ',
    email: 'leona@hotmail.com',
    direccion: "CR 16 # 53 - 12"
}]

We have 3 items but only 2 datums were rendered:
typeahead_suggestion

Why this behaviour? How can I get rendered all items?
Your help will be appreciated.

My javascript code looks like this:

var txb = $("#customers");
var o = {
    webservice: "../Services/AutoComplete.asmx/customerJSON",
    params: { type: "1" },
    display: "nombre",
    hiddenValue: "id",
    hiddenField: "#hdnCustomer"
};

var query = "?prefix=%QUERY";
for (var p in o.params) query += "&" + p + "=" + encodeURIComponent(o.params[p]);
txb.attr({ "placeholder": "Seleccione" }).typeahead({
    limit: 10,
    remote: {
        url: o.webservice + query, dataType: "xml", rateLimitWait: 600,
        filter: function (d) {
            var datums = [];
            var data = $.parseJSON(d.documentElement.textContent);
            for (var i = 0; i < data.length; i++)
                datums.push((function (item) {
                    item.tokens = new Array();
                    var tokens = item[o.display].split(/\b/);
                    for (var n = 0; n < tokens.length; n++)
                        if (tokens[n].length > 2) item.tokens.push(tokens[n]);
                    return item;
                })(data[i]));
            console.log(datums);
            return datums;
        }
    },
    valueKey: o.display,
    header: headerTemplate,
    template: bodyTemplate,
    engine: Hogan
}).on('typeahead:selected', function (e, datum) {
    $(o.hiddenField).val(datum[o.hiddenValue]);
    txb.blur();
}).on('keyup', function () {
    $(o.hiddenField).val("");
});

I think that #215 deals with the issue.

@jherax
Copy link
Author

jherax commented Sep 16, 2013

As suggested in the Issue #215 , I added the attribute allowDuplicates , and the var isDuplicate was modified as shown: Adding an option for allowing duplicates to show in the dataset.

Modify your typeahead.js
...

    this.remote = o.remote;
    this.itemHash = {};
    this.adjacencyList = {};
    this.storage = o.name ? new PersistentStorage(o.name) : null;
--> this.allowDuplicates = o.allowDuplicates || true;
}

...

    var item = that._transformDatum(datum), isDuplicate;
--> isDuplicate = that.allowDuplicates ? false : utils.some(suggestions, function(suggestion) {
        return item.value === suggestion.value;
    });

@dhawalkodeplay
Copy link

Thank you! Was of help.

scorphus pushed a commit to scorphus/cops that referenced this issue Feb 23, 2014
Note that it's a modified version of release 0.9.3 see twitter/typeahead.js#442
I had to keep duplicates.
@sahanDissanayake
Copy link

This issue still exists, http://canalcasting.com/sipc/team.php?search=l# the main section only works with "ev" one result only. But on the network there are more than one result

dunxd pushed a commit to dunxd/mikespub-cops that referenced this issue Sep 10, 2023
Note that it's a modified version of release 0.9.3 see twitter/typeahead.js#442
I had to keep duplicates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants