Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Last active December 21, 2015 22:58
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 nicolasblanco/6378675 to your computer and use it in GitHub Desktop.
Save nicolasblanco/6378675 to your computer and use it in GitHub Desktop.
Twitter Date Picker localized on front and with only ISO sent/retrieved from the server
= f.input :date_of_birth, as: :date_picker
!!! 5
%html(lang="en")
%head
%meta(charset="utf-8")
/ ...
:javascript
window.CurrentLocale = "#{I18n.locale}";
#= require bootstrap-datepicker/js/bootstrap-datepicker
#= require bootstrap-datepicker/js/locales/bootstrap-datepicker.fr
#= require moment/min/moment.min
#= require moment/min/lang/fr
$(document).ready ->
moment.lang(window.CurrentLocale)
$(".datepicker").each (i, field) ->
$(field).val(moment($(field).val()).format('L'))
$(".datepicker").datepicker
language: window.CurrentLocale
.on "changeDate", (en) ->
$(this).next("input[type=hidden]").val(moment(en.date).format("YYYY-MM-DD"))
class DatePickerInput < SimpleForm::Inputs::Base
def input
res = ""
res << @builder.text_field(attribute_name, input_html_options.merge(name: nil, class: "datepicker"))
res << @builder.hidden_field(attribute_name, id: "#{attribute_name}_hidden")
res.html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment