Skip to content

Instantly share code, notes, and snippets.

@blakerego
Created April 15, 2013 15:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blakerego/5388897 to your computer and use it in GitHub Desktop.
Save blakerego/5388897 to your computer and use it in GitHub Desktop.
haml-simple-form-datetime-bootstrap
= simple_form_for([:admin, @announcement]) do |f|
= f.error_notification
- current_profile = Profile.find_by_user_id(@current_user.id)
.form-inputs
= f.input :message, :required => true
= f.hidden_field :profile_id, :value => @current_user.primary_profile.id
= f.fields_for :TvScreen do |tv|
/// STARTS
= tv.input :starts_on, :placeholder => "MM/DD/YYYY", :input_html => {:class => "datepicker date-picker"}, :label => "Announcement starts on"
.input-append.bootstrap-timepicker
= tv.input :starts_at, :input_html => { :id => "starts_at", :class => "input-append bootstrap-timepicker"}, :label => "at "
/// EXPIRES
= tv.input :expires_on, :placeholder => "MM/DD/YYYY", :input_html => {:class => "datepicker date-picker"}, :label => "Announcement expires on"
.input-append.bootstrap-timepicker
= tv.input :expires_at, :input_html => {:id => "expires_at"}, :label => "at"
= tv.hidden_field :timezone
= f.input :location_id, :as => :select, :collection => available_locations, :label_method => :description, :label => 'Building / Location', :include_blank => true, :required => true, :selected => @current_user.primary_profile.location_id
.form-actions
= f.button :submit
:javascript
$(document).ready(function(){
$('input.date-picker').datepicker({autoclose: true});
$('#starts_at').timepicker();
$('#expires_at').timepicker();
// format offset to ruby timezone format
offset = new Date().getTimezoneOffset() / 60;
formatted_offset = String(- offset * 100);
if (formatted_offset.length < 4){
formatted_offset = formatted_offset + "0";
}
$("#announcement_TvScreen_timezone").val(formatted_offset);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment