0

I am trying to change date format for date_field_tag, but i am not getting proper.

code i have used:

<%= date_field_tag 'dob' , '' , value: @search_params[:dob], placeholder: 'YYYY/MM/DD', autocomplete: 'off', class: 'form-control' %>

i need to display format and save yyyy/mm/dd

Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
vvp45
  • 43
  • 9
  • Does this answer your question? https://stackoverflow.com/questions/36926588/rails-format-date-field – Joel Blum May 13 '21 at 06:00
  • On a side note don't use placeholders for this. https://www.smashingmagazine.com/2018/06/placeholder-attribute/#cognition – max May 13 '21 at 10:33

1 Answers1

1
<%= date_field_tag 'dob', @search_params[:dob].to_date.strftime("%Y/%m/%d"),  placeholder: 'YYYY/MM/DD' %>

Note that date_field_tag method signature helper's signature is date_field_tag(name, value = nil, options = {})

Joel Blum
  • 7,750
  • 10
  • 41
  • 60