I would like to automatically save a form when the user selects a date (or makes any change for that matter, whether it be date or time) from the datepicker popup. In rails I’m using a form with :remote => true to simply change a due date attribute. It’s just one field, so it feels like overkill to make users click a ‘submit’ button after picking a date. I currently have it set up to display the updated date using AJAX once the user updates the form, but again, I’d like this done w/o actually clicking a submit button.
Here’s my erb:
<%= form_for todo, :remote => true, :url => update_todo_project_path, :html => {:id => "todo#{todo.id}" } do |f| %>
<%= f.hidden_field :id %>
<%= f.text_field :due %>
<%= f.submit %>
<% end %>
Javascript (just an external js file):
$('input#project_todo_due').datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm'
});
And update_todo.js.erb:
$("#dueon<%= @todo.id%>").html("<%= raw escape_javascript(render(:partial => 'duedate')) %>");
I’m going to take a stab at it:
The docs I used:
jQuery UI Datepicker — onClose
jquery-ujs on Github — relevant lines begin at 362