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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:46:00+00:00 2026-06-08T01:46:00+00:00

This isn’t working as I’d like. I have an entry form for a new

  • 0

This isn’t working as I’d like.

I have an entry form for a new job, which is made up of a number of steps. By default there are 4 new and unsaved steps populated per job.

Using the code from the view below, I am able to attach the jQuery UI datepicker control to the text fields and they appear against the correct input field when i click them.

However, when I select a date from the picker it is only ever going into the field representing the start date of the first step.

<%= form_for @job, :url => jobs_path do |f| %>
    <%= f.label :name %>
    <%= f.text_field :name %>

    <% @job.steps.each do |step| %>
        <%= fields_for "job[step_attributes][]", step do |s| %>
            <%= s.label :name %>
            <%= s.text_field :name %>

            <%= s.label :start_date %>
            <%= s.text_field :start_date, :class => :datepicker %>
        <%= end %>
<% end %>

<script type="text/javascript">
    $(function() {
        $('.datepicker').datepicker({ dateFormat: "dd/mm/yy"});
    });
</script>

I know ultimately this has to do with the generated id attribute for the input elements being the same, was wondering, has anybody successfully overcome this issue?

This fiddle: http://jsfiddle.net/twilson/u9m9L/ demonstrates my problem.

  • 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-06-08T01:46:02+00:00Added an answer on June 8, 2026 at 1:46 am

    First, invoke fields_for on your form builder instead:

    <%= f.fields_for :steps do |s| %>
    

    Second, you don’t need to iterate through @job.steps if you specify the association name to fields_for. There’s an example on how to use it with one-to-many assoiciations here.

    If you still have this problem, paste your generated HTML, it would easier to find the cause.

    EDIT

    OK so the problem is because Rails form builder does not generate child indexes to give unique IDs to nested fieldsets. This most likely happened because the associations are built but not yet saved to the DB. One way I see is to assign child indexes manually, like so:

    <% @job.steps.each_with_index do |step,i| %>
      <%= f.fields_for :steps, step, :child_index => i do |s| %>
    

    See if that helps.

    This is a somewhat contrived scenario given that you have only new objects. To be able to dynamically add/remove nested items, this would be a bit trickier. You can see how this can be dealt with in the nested model Railscasts.

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

Sidebar

Related Questions

This isn't a real fluent interface. I have an object which builds up a
This isn't working in visual studio 2010 , it gives me the following error
This isn't meant as a troll or flamebait or anything like that. I've been
This isn't working. I'm trying to replicate the animate to red and then remove
This isn't working in IE (although it does work in FFX). Why? Using HTML
This isn't working the way I expect it to. Sample input will include an
This isn't a question on proper coding practice, I'm just working through the semantics.
This isn't about a specific problem I'm having, but I have to clear something
This isn't working: $.ajax({url: PStoreZoomArea.php, type: get, data: {mapza: mapZoomArea, mapc: mapCenter, mapz: mapZoom}})
This isn't a huge problem, but ideally i'd like to sort it out if

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.