joeyk16
joeyk16

Reputation: 1415

Rails form date_field is showing mm/dd/yyyy

Before I input anything into the rails form. The date_field is showing mm/dd/yyyy.

Is their a way for it to show dd/mm/yyyy.

Placeholder doesn't work.

I have looked around for an answer but none of the answers worked.

Thank you.

Here is the form data.

.flex.flex-column.w50p.mx-auto
  = form_for :agreegated_answer, url: survey_aggregated_answers_path(@survey), method: :post  do |f|
    = f.label :procedures_that_have_tags
    = f.collection_select(:tag_ids, @survey.tags, :name, :name, { selected: [] },
      multiple: true, class: 'js-input-tags border-light', placeholder: 'Select tags')
    = f.label :answered_from
    = f.date_field :start_from
    = f.label :answered_to
    = f.date_field :ends_from
    = f.submit 'Generate results'

enter image description here

Upvotes: 0

Views: 2856

Answers (3)

puneet18
puneet18

Reputation: 4427

Use strftime function of ruby:

= f.date_field :start_from, value: @survey.start_from.strftime("%d/%m/%Y")

Upvotes: 1

joeyk16
joeyk16

Reputation: 1415

The problem is my computer.

When im on someone elses computer it's dd/mm/yyyy when im on mine its mm/dd/yyy because my computer is American.

Upvotes: 0

Ritesh Ranjan
Ritesh Ranjan

Reputation: 1012

Try this:

<%= f.date_field :ends_from, as: :date, value: f.object.try(:strftime,"%d/%m/%Y") %>

Upvotes: 1

Related Questions