Styling the date fields of a Rails date_select

不羁岁月 提交于 2019-12-10 16:12:36

问题


In Rails' forms, date select drop-downs are easy:

<%= f.label :my_date %>
<%= f.date_select :my_date %>

Then I get 3 select drop-downs for the year, month and day. Is there an easy way to add HTML between these select elements without using JavaScript? I want to be able to style and label them nicer.


回答1:


Convert it to a text field and add a JQuery datepicker or similar.

Theres a good guide here, http://railscasts.com/episodes/213-calendars




回答2:


You can easily style them with CSS as each part of date_select is postfixed with '_1i', '_2i' etc . For a date_select with id 'my_date' you can use

#my_date_1i  // the year
#my_date_2i  // the month
#my_date_3i  // the day

Hope this helps

Cheers



来源:https://stackoverflow.com/questions/15860467/styling-the-date-fields-of-a-rails-date-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!