Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI datepicker within rails nested forms

I am very beginner to ruby on rails and web-development.

I created my app that similar to Ryan Bates, episode 197 and 198, but with use JQuery UI datepicker. But I dont really know how to do that. I know that the problem is with element ID always same whatever I generated new dynamic partial. For example, when I choose a day, it works fine. but when I add new nested model (or record), only the first nested model change.

I use ruby 1.8.7 and rails 2.3.1, I must use thses versions.

Please I was struggling with this. Any help will 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>
like image 461
Fez Avatar asked Dec 02 '25 06:12

Fez


1 Answers

Why don't you try this:

<script type="text/javascript">
$(function() {
  $('.datePicker').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>
like image 115
Arun Avatar answered Dec 04 '25 20:12

Arun