Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:16+00:00 2026-05-27T02:39:16+00:00

I am using jQuery autocomplete which is working fine with existing element but not

  • 0

I am using jQuery autocomplete which is working fine with existing element but not with dynamically added element.

Here is my autocomplete code (Which I have changed a bit)

$(function() {

        (function( $ ) {
        $.widget( "ui.combobox", {
            _create: function() {
                var self = this,
                    select = this.element.hide(),
                    selected = select.children( ":selected" ),
                    value = selected.val() ? selected.text() : "";
                var input = this.input = $( ".editableCombobox" )    // your input box
                    //.insertAfter( select )
                    .val( value )
                    .autocomplete({
                        delay: 0,
                        minLength: 0,
                        source: function( request, response ) {
                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                            response( select.children( "option" ).map(function() {
                                var text = $( this ).text();
                                if ( this.value && ( !request.term || matcher.test(text) ) )
                                    return {
                                        label: text.replace(
                                            new RegExp(
                                                "(?![^&;]+;)(?!<[^<>]*)(" +
                                                $.ui.autocomplete.escapeRegex(request.term) +
                                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                            ), "$1" ),
                                        value: text,
                                        option: this
                                    };
                            }) );
                        },
                        select: function( event, ui ) {
                            ui.item.option.selected = true;
                            self._trigger( "selected", event, {
                                item: ui.item.option
                            });
                        },
                        change: function( event, ui ) {
                            if ( !ui.item ) {
                            var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                                valid = false;
                                select.children( "option" ).each(function() {
                                if ( $( this ).text().match( matcher ) ) {
                                this.selected = valid = true;
                                return false;
                                }
                                });
                                //if ( !valid ) {
                                    // remove invalid value, as it didn't match anything
                                    //$( this ).val( "" );
                                    //select.val( "" );
                                    //input.data( "autocomplete" ).term = "";
    //return false;
        //                      }
                            }
                        }
                    })
                    .addClass( "ui-widget ui-widget-content ui-corner-left" );

                input.data( "autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                        .data( "item.autocomplete", item )
                        .append( "<a>" + item.label + "</a>" )
                        .appendTo( ul );
                };

                this.button = $( "<button type='button'>&nbsp;</button>" )
                    .attr( "tabIndex", -1 )
                    .attr( "title", "Show All Items" )
                    .insertAfter( input )
                    .button({
                        icons: {
                            primary: "ui-icon-triangle-1-s"
                        },
                        text: false
                    })
                    .removeClass( "ui-corner-all" )
                    //.addClass( "ui-corner-right ui-button-icon" )
                    .live('click',function() {
                        // close if already visible
                        if ( $(this).prev().autocomplete( "widget" ).is( ":visible" ) ) {
                            $(this).prev().autocomplete( "close" );
                            return;
                        }

                        // work around a bug (likely same cause as #5265)
                        $( this ).blur();

                        // pass empty string as value to search for, displaying all results
                         $(this).prev().autocomplete( "search", "" );
                         $(this).prev().focus();
                    });
            },

            destroy: function() {
                this.input.remove();
                this.button.remove();
                this.element.show();
                $.Widget.prototype.destroy.call( this );
            }
        });
    })( jQuery );

        $( "#combobox" ).combobox();
        $( "#toggle" ).live('click',function() {
            $( "#combobox" ).toggle();
        });

        });  

Here is my code which adds new element

var selectedRow = $('#contactGroup'+rowId);
    var clonedRow = selectedRow.clone();  
selectedRow.after(clonedRow);   

After reading many similar questions I think .live might help but not sure where to use it.

EDIT:

I tried removing live.

New code for Autocomplete

$(function() {

        (function( $ ) {
        $.widget( "ui.combobox", {
            _create: function() {
                var self = this,
                    select = this.element.hide(),
                    selected = select.children( ":selected" ),
                    value = selected.val() ? selected.text() : "";
                var input = this.input = $( ".editableCombobox" )    // your input box
                    //.insertAfter( select )
                    .val( value )
                    .autocomplete({
                        delay: 0,
                        minLength: 0,
                        source: function( request, response ) {
                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                            response( select.children( "option" ).map(function() {
                                var text = $( this ).text();
                                if ( this.value && ( !request.term || matcher.test(text) ) )
                                    return {
                                        label: text.replace(
                                            new RegExp(
                                                "(?![^&;]+;)(?!<[^<>]*)(" +
                                                $.ui.autocomplete.escapeRegex(request.term) +
                                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                            ), "$1" ),
                                        value: text,
                                        option: this
                                    };
                            }) );
                        },
                        select: function( event, ui ) {
                            ui.item.option.selected = true;
                            self._trigger( "selected", event, {
                                item: ui.item.option
                            });
                        },
                        change: function( event, ui ) {
                            if ( !ui.item ) {
                            var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                                valid = false;
                                select.children( "option" ).each(function() {
                                if ( $( this ).text().match( matcher ) ) {
                                this.selected = valid = true;
                                return false;
                                }
                                });
                                //if ( !valid ) {
                                    // remove invalid value, as it didn't match anything
                                    //$( this ).val( "" );
                                    //select.val( "" );
                                    //input.data( "autocomplete" ).term = "";
    //return false;
        //                      }
                            }
                        }
                    })
                    .addClass( "ui-widget ui-widget-content ui-corner-left" );

                input.data( "autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                        .data( "item.autocomplete", item )
                        .append( "<a>" + item.label + "</a>" )
                        .appendTo( ul );
                };

                this.button = $( "<button type='button'>&nbsp;</button>" )
                    .attr( "tabIndex", -1 )
                    .attr( "title", "Show All Items" )
                    .insertAfter( input )
                    .button({
                        icons: {
                            primary: "ui-icon-triangle-1-s"
                        },
                        text: false
                    })
                    .removeClass( "ui-corner-all" )
                    .addClass( "ui-corner-right ui-button-icon" )
                    .click(function() {
                        // close if already visible
                        if ( $(this).prev().autocomplete( "widget" ).is( ":visible" ) ) {
                            $(this).prev().autocomplete( "close" );
                            return;
                        }

                        // work around a bug (likely same cause as #5265)
                        $( this ).blur();

                        // pass empty string as value to search for, displaying all results
                         $(this).prev().autocomplete( "search", "" );
                         $(this).prev().focus();
                    });
            },

            destroy: function() {
                this.input.remove();
                this.button.remove();
                this.element.show();
                $.Widget.prototype.destroy.call( this );
            }
        });
    })( jQuery );

        $( "#combobox" ).combobox();
        $( "#toggle" ).click(function() {
            $( "#combobox" ).toggle();
        });

        });

Binding newly added element in clone method

 var selectedRow = $('#contactGroup'+rowId);
        var clonedRow = selectedRow.clone();  
    selectedRow.after(clonedRow);   
 $(('#contactGroup'+rowId) .editableCombobox).autocomplete( "search", "" );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:39:16+00:00Added an answer on May 27, 2026 at 2:39 am

    You can’t use ‘live’ on autocomplete, as far as I know.

    Place your autocomplete options in a function that expects the field as parameter, on which you want to apply the autocomplete method.

    function enable_autocomplete(InputField) {
        $(InputField).autocomplete({
            source: availableTags
        });
    }
    

    Then, after cloning the field, call this function with the cloned field.

    enable_autocomplete(ClonedField);
    

    I’ve written you an easy example, what makes it much easier to understand what I am trying to say 😉

    Edit: I’ve written another example based on the combobox example from jQueryUIs website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have an autocomplete functionality using jquery, and I've encountered ZendX_JQuery which
I am using jQuery Autocomplete with JSON but the resulting data is not displaying
The following autocomplete code works with Jquery 1.4.4 but not with 1.5.1. I am
I have a jQuery autocomplete fild which gets existing data from my MVC action.
I'm using jquery autocomplete <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script> Everything is working Ok., but now
I have an input box for which I am using the Jquery autocomplete function.
I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return
I'm using the jQuery autocomplete plugin to get a list of locations, which works
Am using JQuery Autocomplete on my templete, but as i get the results the
I am using the following code to dynamically create an INPUT element and assign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.