JQuery UI datepicker in rails of nested forms

I am very new to hacking rails and web development.

I created my application, similar to Ryan Bates, episodes 197 and 198, but using the jQuery UI datepicker. But I do not know how to do this. I know that the problem with the element identifier is always the same, regardless of the fact that I created a new dynamic partial. For example, when I select a day, it works great. but when I add a new nested model (or record), only the first nested model changes.

I am using ruby ​​1.8.7 and rails 2.3.1, I have to use these versions.

Please, I struggled with this. Any help would be appreciated.

<script type="text/javascript">
$('.datePicker').each(function() {
$(this).datepicker();
});
</script>
<div class ="fields">
  <%= f.select(:assessmethods_id,@types,:include_blank=>true) %>  
  <%= f.text_field(:assessdate,:class => "datePicker") %>
  <%= link_to_remove_fields("remove", f) %>
</div>
+3
source share
1 answer

Why don't you try this:

<script type="text/javascript">
$(function() {
  $('.datePicker').each(function() {
    $(this).datepicker();
  });
});
</script>
<div class ="fields">
  <%= f.select(:assessmethods_id,@types,:include_blank=>true) %>  
  <%= f.text_field(:assessdate,:class => "datePicker") %>
  <%= link_to_remove_fields("remove", f) %>
</div>
+2
source

All Articles