需要内联日期,月份和年份选择标签

时间:2014-12-23 04:41:36

标签: javascript html css ruby-on-rails-4 datepicker

我在编辑用户个人资料页面中有一个生日字段,如图所示

enter image description here

我想让它以这种方式水平显示

enter image description here

到目前为止,我正在使用以下代码,

访问者/ edit.html.erb,

<%= simple_form_for([@user],:url => visitor_path(@user), method: :put, :class => 'form form-horizontal') do |f| %>
  <%= f.label :birthday %>      
  <div class="form-group">
    <div class="col-sm-2">
      <%= birthday_field_for(f, end_year: Date.today.year) %>
    </div>
  </div>
<% end %>

在application_helper.rb中,

def birthday_field_for(form,options={})
  date_field_for(form,:birthday,options.reverse_merge!(start_year: Date.today.year - 90, end_year: Date.today.year - 13))
end

def date_field_for(form,field,options={})
  form.date_select(field, options.reverse_merge!(order: [:day, :month, :year],
                                               include_blank: true))
end

请帮我解决问题。

1 个答案:

答案 0 :(得分:0)

感谢您的回答!

选择容器的宽度设置为100%。因为下一个选择选项卡出现在新行中。

在visitor / edit.html.erb中添加css,确实解决了我的问题,

<% content_for :head_css do %>
  <style type="text/css">
    .select2-container {
      width: 120px !important;
    }
  </style>
<% end %>