Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert one css class to select on Rails date_select

I am using the method date_select to generate 3 html selects, day, month and year. But I need that each select has one class of CSS.

I have not found on documentation how to pass parameters to helper, I tried several ways and nothing.

Rails View:

<%= f.date_select :birthday, :order => [:day, :month, :year], :start_year => 1910, :end_year => 2012, :html => {:class => ['day', 'month', 'year']} %>

HTML output:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]">

HTML output like I do:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]" class="day">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]" class="month">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]" class="year">

Thanks!

like image 747
Hugo Demiglio Avatar asked Apr 05 '12 15:04

Hugo Demiglio


1 Answers

They way I worked around this problem was with css

View

<span class="datetime"> <%= f.date_select :birthdate, :order => [:day, :month, :year], :start_year => 1910, :end_year => 2012 %></span>

CSS

.datetime select:nth-child(1){
  width: 130px;
  text-indent: 15px; 
}

.datetime select:nth-child(2) {
  width: 200px;
  text-indent: 5px;
}

.datetime select:nth-child(3) {
  width: 110px;
  text-indent: 15px;
}
like image 200
goma Avatar answered Nov 01 '22 16:11

goma