Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby simple_form renders 3 fields for date input

I am using the ruby gem simple_form for different forms around my site and was wondering if there was a way to combine/collapse the date input that is rendered 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 produces three input field: day, month and year. But what I actually want is to have a single field for all the three, so the input could look like "05/05/1980". How can that be achieved?

like image 923
Severin Avatar asked Nov 07 '13 11:11

Severin


2 Answers

In order to use html5 date fields you can do the following:

= f.input :dob, as: :string, input_html: {type: :date}
like image 170
coorasse Avatar answered Sep 22 '22 17:09

coorasse


You passed :as param with wrong. using string type will make one field instead of 3 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]
like image 36
Chen Avatar answered Sep 26 '22 17:09

Chen