Rails 3.1 text_field form helper and jQuery datepicker date format

前端 未结 4 891
死守一世寂寞
死守一世寂寞 2021-01-06 04:19

I have a form field in my Rails view like this:

<%= f.text_field :date, :class => \"datepicker\" %>

A javascript function converts

4条回答
  •  梦谈多话
    2021-01-06 04:26

    JQuery datepicker won't format the pre-populated date.
    You would need to handle it on the rails side by using the formatted date with the textfield, instead of the raw date which has the default 'yyyy-mm-dd' format.

    Example -

    <%= f.text_field :date, :class => "datepicker", :value => @model.date.strftime("%d %m %Y") %>
    

    More examples @ Rails date format in a text_field

提交回复
热议问题