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

Autocomplete from remote source json? #757

Closed
deronsizemore opened this issue Apr 5, 2015 · 4 comments
Closed

Autocomplete from remote source json? #757

deronsizemore opened this issue Apr 5, 2015 · 4 comments

Comments

@deronsizemore
Copy link

Can someone point me to an example of this in action? I found a basic example here: #683 (comment) but I'm still not sure how to specify a remote url (which returns a json reponse) and the problem is as soon as I click inside of the input field, the drop down appears. Is there a way to not show the drop down until the user starts typing and then only show the drop down if there's data that matches what they're typing?

Just to give you an idea of what I'm after, here's an example: http://goodies.pixabay.com/jquery/tag-editor/demo.html. They have an autocomplete example that works well.

Sorry if this is obvious.

@shoaibshakeel381
Copy link

You can use it like this:

var $name = $('select#complete'),selectize({
    valueField: 'Id',
    labelField: 'Name',
    searchField: 'Name',
    options: [],
    persist: false,
    loadThrottle: 600,
    create: false,
    allowEmptyOption: true,
    load: function(query, callback) {
        if (!query.length) return callback();
        $.ajax({
            url: YOURURLHERE,
            type: 'GET',
            dataType: 'json',
            data: {
                name: query,
                additionalDataIfRequired: 'Additional Data'
            },
            error: function() {
                callback();
            },
            success: function(res) {
                // you can apply any modification to data before passing it to selectize
                callback(res);
                // res is json response from server
                // it contains array of objects. Each object has two properties. In this case 'id' and 'Name'
                // if array is inside some other property of res like 'response' or something. than use this
                //callback(res.response);
            }
        });
    }
})[0].selectize;

@msurguy
Copy link

msurguy commented May 11, 2015

@deronsizemore can we close this issue now?

@deronsizemore
Copy link
Author

Sorry for the delay. Have a newborn at home and it's tough to find time to do much online at the moment. I haven't had the chance to try this year, but sure, close it and if i get stuck when i get the chance to try it I'll post back. I appreciate your help.

@msurguy
Copy link

msurguy commented May 12, 2015

no problem @deronsizemore! The baby is the most important! Thanks for stopping by.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants