Ruby simple_form displays 3 fields for entering date

I use ruby ​​gem simple_form for different forms around my site and wondered if there is a way to combine / collapse date input, which is displayed by default:

= f.input :dob, label: "Date of Birth", as: :date, start_year: Time.now.year - 90, end_year: Time.now.year - 8, order: [:day, :month, :year]

This code creates three input fields: day, month, and year. But I really want to have one field for all three, so the input may look like "05/05/1980". How can this be achieved?

+4
source share
5 answers

You passed: as a parameter with the wrong one. using the string type, you will create one field instead of three fields.

= f.input :dob, label: "Date of Birth", as: :string, start_year: Time.now.year - 90, end_year: Time.now.year - 8, order: [:day, :month, :year]
+5
source

To use html5 date fields, you can do the following:

= f.input :dob, as: :string, input_html: {type: :date}
+6

jquery datepicker. default datepicker . .

+1

A better solution is text with an optional datepicker.

Check this Railscast http://railscasts.com/episodes/213-calendars

0
source

Use jquery datepicker as:

= f.input :dob

and

$(function() {
  $("input#id_of_dob_field").datepicker();
});
0
source

All Articles