I have simple_form input which takes input of datetime.
= f.input :input, as: :datetime, start_year: DateTime.now.year, label: false, selected: DateTime.now
That code is working, but there's separator between date and time. The format is looks like this.
"%d %B %Y-%H:%M"
What could I do so the format will be like this?
"%d %B %Y %H:%M"
I've tried this solution, but there's nothing changed.
Code using this solution method:
= f.input :input, as: :datetime, date_separator: '', time_separator: '', start_year: DateTime.now.year, label: false, selected: DateTime.now
Magic option: datetime_separator: ""
Related
I would like to change the month select input from date_select : change the values of the array (with January, February... to Janvier, Février...). And I would also like to append styling to each select box (day, month and year). This is my date_select
<%= f.date_select :birthdate,
order: [:day, :month, :year],
prompt: { day: 'Jour', month: 'Mois', year: 'Année' },
start_year: Date.today.year - 13,
end_year: Date.today.year - 100
%>
I don't seem to find anything on the rails official documentation. Any help? Thanks :)
I guess below code would help you.
<%= f.date_select :birthdate,
{
order: [:day, :month, :year],
prompt: { day: 'Jour', month: 'Mois', year: 'Année' },
start_year: Date.today.year - 13,
end_year: Date.today.year - 100,
locale: :fr
},
{class: 'custom-style'}
%>
I guess setting f.date_select ... locale: :fr will help
Use the use_month_names option to set custom values for the months:
<%= f.date_select :birthdate,
{
order: [:day, :month, :year],
prompt: { day: 'Jour', month: 'Mois', year: 'Année' },
start_year: Date.today.year - 13,
end_year: Date.today.year - 100,
use_month_names: ["Janvier", "Février", etc..]
},
{ class: "some-css-class-for-styling" }
%>
So I have the following line:
<%= f.input :birth_date, as: :date, label: "Date of Birth", html5: true, input_html: {min: Time.now.year - 100.year, max: Time.now} %>
Which is generating:
<input class="form-Field-control date required dr-FormField-control" aria-invalid="true" name="recommends_insurance_term_life_referral[birth_date]" id="recommends_insurance_term_life_referral_birth_date" type="date">
Any thoughts as to that for which I had not accounted?
As min and max you have to pass a Date object.
Date.today - 100.years
Hello I am trying to make a date_select and the class wont take effect. Thanks for all the help.
<%= f.date_select :created_at,
:order => [:month, :day, :year],
:prompt => {month: 'Birth Month', day: 'Birth Day', year: 'Birth Year'},
:start_year => Time.now.year,
:end_year => 1920,
:class => 'SelectDropDown' %>
the form helper that I like is called simple_form. When I need to add a date picker I have been using bootstrap3-datetimepicker-rails
Setup:
File #app/assets/javascripts/application.js
$(document).ready(function() {
$('.datetimepicker').datetimepicker({});
return $('.datepicker').datetimepicker({
format: 'YYYY/MM/DD'
});
});
});
Now to apply it to a form
= f.input :date_select, as: :string, input_html: { class: 'datetimepicker', value: "#{f.created_at}" }
I hope that this helps
try to use html_options for class:
<%= f.date_select :created_at,
order: [:month, :day, :year],
prompt: {month: 'Birth Month', day: 'Birth Day', year: 'Birth Year'},
start_year: Time.now.year,
end_year: 1920,
html_options: {class: "SelectDropDown"} %>
for more details check data_select
I have 2 date fields, date started and date finished. I want to have a prompt for each, as in like on the page's first load, it will display the text "please select".
As you can see the code below, I have included prompt but it is not working.
<%= f.input :year_started, prompt: "Please select", as: :date, label: "Date started", start_year: Date.today.year, end_year: Date.today.year - 100, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' }, :required => false %>
<%= f.input :year_finished, prompt: "Please select", as: :date, label: "Date finished", start_year: Date.today.year + 7, end_year: Date.today.year - 100, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' }, hint: "Or expected graduation month and year.", :required => false %>
Can someone please help me how to get this done in date select. Thanks
I have been attempting to adjust the size of my form fields. I have tried using size like so...
<%= f.date_select(:form_date, order: [:month, :day, :year], prompt: { month: 'Select Month', day: 'Select Day', year: 'Select Year' }, start_year: 2000, size: 1) %>
Am I just entering size in the wrong order (size: 1 shouldn't be last)? Is this best handled in my stylesheets?
Thanks in advance.
Turns out I was mixing options and html_options
date_select(object_name, method, options = {}, html_options = {}) Link
Here is what I changed my line of code to from above...
<%= f.date_select(:form_date, options = { order: [:month, :day, :year], prompt: { month: 'Select Month', day: 'Select Day', year: 'Select Year' }, start_year: 2000 }, html_options = { size: 1 }) %>