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

http://railscasts.com/episodes/102-auto … on-revised

and also reading the

http://jqueryui.com/demos/autocomplete/ … 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" ).menu.active ) {
                    event.preventDefault();
                }
            })
            .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
                    terms.pop();
                    // 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} %>
        </div>

and in my tags path is...

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

        end

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)