Order year in rails date_select - ruby-on-rails

f.date_select(:birthday, prompt: {
day: 'Select day', month: 'Select month', year: 'Select year'
}, end_year: Time.now.year-13, start_year: 1900, required: true)
It shows start_year first and end_year last:
1900
1901
..
..
2002
I want 2002 first and 1900 at the bottom of the select box.
Couldn't find anything in rails documentation and google. Any help will be appreciated. Thanks

Simply exchanging end_year and start_year will do the trick.
In your case:
f.date_select(:birthday, prompt: {
day: 'Select day', month: 'Select month', year: 'Select year'
}, end_year: 1900, start_year: Time.now.year-13, required: true)

Related

Custom date_select values in Rails?

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" }
%>

Rails date_select class not working

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

How to remove datetime separator in simple_form?

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: ""

Helper date_select. How validate dates 30 and 31 of february?

I have model Freelancer and tables freelancers with property birthday, type date.
freelancers/edit.html.erb
<li class="form-fields__group form-fields__group_birthdate">
<label for="freelancer_birth_date">Birthday</label>
<div class= "field">
<%= f.date_select :birthday, { prompt: { day: 'Select day',
month: 'Select month',
year: 'Select year' },
include_blank: true, start_year: Time.now.year - 70},
{ class: 'form-control_medium'} %>
</div>
</li>
If I selcet february 30 or 31 return value 3 march. How me validate value date 30 and 31 if I selected february? Thank you

How to adjust date_select / time_select field size

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 }) %>

Resources