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 906863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:27:25+00:00 2026-05-15T16:27:25+00:00

I have a page that uses Ryan Bates nested_form plugin . The plugin is

  • 0

I have a page that uses Ryan Bates nested_form plugin. The plugin is used when you have form based on one model and then additional fields that belong to another model. For example if I had a form that created categories, and at the same time I wanted to add items to the new category, my form would contain input fields for the category model and input fields for items I want to assign to the new category.

Ryan’s plugin uses jQuery to create a button that adds additional input fields as the user might what to add 2 items or 10 items to the category.

In my case, I am adding People to a Report. This is done through ‘links’. My nested form works nicely, but I also want these new input fields to be autocompletable. To do this I am using the jQuery UI 1.8 autocomplete widget. It is working nicely in other parts of my app. But it is not working on this nested form.

The problem seems to be that my javascript that makes textfields autocompletable, loads once on document ready.

Then later, when I add new textfields in my nested_form, the autocomplete widget does not get attached to these as it has already loaded once.

I could be wrong but this is just my guess. Could anyone suggest what to do. Below is my autocomplete code (I have not shown the nested_form javascript as it is all hidden away in the plugin, and I don’t really want to change any of it. It’s good enough to know that it works and now I need to make my autocomplete widget accommodate for this).

This is the page with javascript:

<script>
// origin_person auto selector
    $(function() {

    $('[id$=origin_id]').autocomplete({
    minLength: 2,
    source: '/people.json',
    focus: function(event, ui) {
        $('[id$=origin_id]').val(ui.item.person.given_name);
        return false;
    },
    select: function(event, ui) {
        $('[id$=origin_id]').val(ui.item.person.given_name);
   $('[id^=hidden_origin]').val(ui.item.person.id);
        return false;
    }
})

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

<!-- Start of form partial for my new report view -->

<% f.fields_for :links do |link_form| %>
  <%= link_form.text_field :origin_id %>
  <%= link_form.text_field :rcvd_id %> 

<%= link_form.link_to_remove "Remove this link" %> 

<% end %>

<%= f.link_to_add "Add a link", :links %>
<!-- The above link_to_add helper is part of the nested_form plugin. 
Using jQuery it will insert the following fields. Notice that the IDs 
are also dynamic which I am trying to connect to. -->

<!-- <input type="text" size="30" name="report[links_attributes][1278921811834][origin_id]" 
      id="report_links_attributes_1278921811834_origin_id" class="ui-autocomplete-input" 
      autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">

      <input name="link[origin_id]" id="hidden_origin_id" class="ui-autocomplete-input" 
      autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
-->

Please point me in the right direction on how to get my autocomplete to grab the newly inserted textfields.

Dale

  • 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-15T16:27:25+00:00Added an answer on May 15, 2026 at 4:27 pm

    Dale, just a stab in the dark. Given the following:

    $(function() { $('[id$=origin_id]').autocomplete({...});
    

    Can the function be used with the .live or .livequery events? If so, this may allow you to keep the integrity in place without further code changes.

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

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As per current development is concerned, I think IsOverflowItem is… May 16, 2026 at 10:17 am
  • Editorial Team
    Editorial Team added an answer Well, Apple recommends not to use _ as the first… May 16, 2026 at 10:17 am
  • Editorial Team
    Editorial Team added an answer @Haim's code works but I think he was asking how… May 16, 2026 at 10:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a page that uses the jQuery.swfobject plugin to embed 5 flash items
I have an ASP Page that uses two listboxes and a third party control
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when
I have a page that uses a bit of jQuery and an effect called
I have a page that uses jQuery to create a number of <input> DOM
I have a page that uses GridView to display some data taken from a
I have a page that uses jQuery UI, and calls the datepicker on 2
I have a page that uses an AJAX request (using Prototype's Ajax.Request()) to validate
I have a page that uses jQuery with a small glitch. I managed to
i have some header tabs on a basic index.aspx page that uses a masterpage.

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.