rene
rene

Reputation: 111

Symfony3 type-ahead / auto complete

I'm looking for an good example for a type-ahead or auto-complete textbox in Symfony3. When entering text in the textbox then a query is executed to search in a database and the results can be selected.

Any suggestion how to implement this in Symfony3? Where to find a good working example?

Upvotes: 0

Views: 608

Answers (2)

fabionvs
fabionvs

Reputation: 197

A code from a project I used these days using Jquery, FosJsRouting and Typeahead:

$('input.typeahead').typeahead({
        highlight: true,
        source: function (valor, process) {
            var search = Routing.generate('YOUR_ROUTE_NAME', {value: value});                
                return $.get(search, function (data) {
                    states = [];
                    map = {};
                    $.each(data, function (i, state) {
                        map[state.id] = state;
                        states.push(state.id);
                    });
                    return process(states);
                });                
        },
        updater: function (item) {
            //After select use the option you selected
            $(".table tbody").append('<tr><td>map[item].id</td></tr>');

        },
    });

I used id as the parameter I wanted to choose from Json, but you could choose any parameter.

Upvotes: 0

Alvin Bunk
Alvin Bunk

Reputation: 7764

You can use typeahead.js as a JQuery include: https://twitter.github.io/typeahead.js/

Here is a simple example: https://twitter.github.io/typeahead.js/examples/

It should be easy to do in Symfony regardless.

Upvotes: 1

Related Questions