Created
October 15, 2014 15:44
-
-
Save ivarvong/fb1682acd5eec3d78308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('body').on('click', '.set-to-now', function(e) { | |
e.preventDefault(); | |
var target_selector = $(this).attr('data-target'); | |
var year = $(target_selector+'_1i'); | |
var month = $(target_selector+'_2i'); | |
var day = $(target_selector+'_3i'); | |
var hour = $(target_selector+'_4i'); | |
var minute = $(target_selector+'_5i'); | |
// var current = [year, month, day, hour, minute].map(function(item) { | |
// return item.val(); | |
// }); | |
var now = new Date(); | |
year.val( now.getFullYear() ); | |
month.val( now.getMonth()+1 ); | |
day.val( now.getDate() ); | |
hour.val( now.getHours() ); | |
minute.val( now.getMinutes() ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming your model is "Post" and the form has something like:
<%= f.datetime_select :published_at %> <a href="#" class="set-to-now" data-target="#post_published_at">NOW</a>