Last active
December 21, 2015 22:58
-
-
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
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
= f.input :date_of_birth, as: :date_picker |
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
!!! 5 | |
%html(lang="en") | |
%head | |
%meta(charset="utf-8") | |
/ ... | |
:javascript | |
window.CurrentLocale = "#{I18n.locale}"; |
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
#= 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")) |
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
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