Bootstrap 日期选择器默认值 simple_form_for [英] Bootstrap datepicker default value simple_form_for

查看:48
本文介绍了Bootstrap 日期选择器默认值 simple_form_for的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用引导程序日期选择器来启用使用 simple_form_for 的表单中的日期选择.例如

I am using the bootstrap date picker to enable selection of dates in a form using simple_form_for. For example

  <%= f.input :payment_date, as: :string, input_html: { class: "datepicker" } %>

我的日期选择器使用 dd-mm-yyyy 格式

My date picker uses the format of dd-mm-yyyy

我想使用 simple_form_for 将今天的日期设置为表单中的默认值,关于如何做到这一点的任何想法?

I would like to set today's date as the default value in the form using simple_form_for, any ideas on how I can do that?

推荐答案

<%= f.input :payment_date, as: :string, input_html: { class: "datepicker", value: Time.now.strftime('%d-%m-%Y') } %>   

它的另一种格式是:(使用活动管理 gem)

Another format to it is: (working with active admin gem)

f.input :date, as: :date_picker, :input_html => { :value => Date.today}

这篇关于Bootstrap 日期选择器默认值 simple_form_for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆