Topic: using rails with jquery ui autocomplete, only first result appears

i was wondering why this autocompletes only one time. ive been watching the railscasts … on-revised

and also reading the … le-remote.

i have the new plug in, not using the old plug in that has 'multiple' as an option. this is supposed to be an input field of tags, exactly like the jquery link above. ie if i type "Java" i can hit the space bar, and then type "Strings", however only "Java" appears and it stops.

    $(function() {
        function split( val ) {
            return val.split( /,\s*/ );
        function extractLast( term ) {
            return split( term ).pop();

        $( "#lesson_tag_name" )
            // don't navigate away from the field on tab when selecting an item
            .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                        $( this ).data( "autocomplete" ) ) {
                source: $('#lesson_tag_name').data('autocomplete-source'),
                search: function() {
                    // custom minLength
                    var term = extractLast( this.value );
                    if ( term.length < 1 ) {
                        return false;
                focus: function() {
                    // prevent value inserted on focus
                    return false;
                select: function( event, ui ) {
                    var terms = split( this.value );
                    // remove the current input
                    // add the selected item
                    terms.push( ui.item.value );
                    // add placeholder to get the comma-and-space at the end
                    terms.push( "" );
                    this.value = terms.join( " " );
                    return false;

however im really not sure what is wrong. the jquery link has the model code for using the multiple autocomplete. the only difference is where the source is coming from.

as opposed to...

                    source: function( request, response ) {
                    $.getJSON( "search.php", {
                        term: extractLast( request.term )
                    }, response );

i only have...

    source: $('#lesson_tag_name').data('autocomplete-source')

which is coming from my view

        <div class="tags">
            <%= f.label :tag_name, "Tags" %>
            <%= f.text_field :tag_name, data: { autocomplete_source: tags_path} %>

and in my tags path is...

        def index
            @tags = Tag.order(:name).where("name like ?", "%#{params[:term]}%")
            render json:{ |tag| {:label => "#{} x #{tag.count}", :value =>} }


but what is wrong with my jquery code? after i hit the first autocomplete, it works and correctly adds a space afterwards. however when i begin typing again, nothing drops down. could someone please help. thanks.

Last edited by stargirlcrystalchan (2012-04-17 16:16:16)