Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial value ignores the format specified #45

Open
vitobotta opened this issue Jan 27, 2020 · 1 comment
Open

Initial value ignores the format specified #45

vitobotta opened this issue Jan 27, 2020 · 1 comment

Comments

@vitobotta
Copy link

Hi! Thanks for this controller. Everything works for me apart from the formatting of the initial value. I am using the controller like this:

        <%= f.text_field :published_at,
          class: "form-text",
          data: {
            controller: "datetime-picker",
            datetime_picker_enable_time: true,
            datetime_picker_alt_format: "D, F j Y at h:i K",
            datetime_picker_date_format: "D, F j Y at h:i K",
            datetime_picker_time_24hr: false,
            datetime_picker_min_date: 10.years.ago
          } %>

When I select a date/time, it is formatted as expected in the text field. However when the flatpikr is first rendered, the current value of published_at is displayed as "2020-01-27 21:06:07 +0200" in the input field. How can I ensure that the initial value is formatted as "D, F j Y at h:i K" too? Thanks!

@abhinaykumar
Copy link
Contributor

abhinaykumar commented Aug 24, 2020

I tried reproducing the issue with settings below but I could not. Also, with default setup datetime-picker does not work for me, I'm guessing it requires some package to be installed.

@vitobotta assuming you want to only format the date in a certain format, can you try something like below?

<%= f.text_field :published_at,
          class: "form-text",
          data: {
            controller: "flatpickr",
            flatpickr_enable_time: true,
            flatpickr_date_format: "D, F j Y at h:i K"
          } %>

@adrienpoly not sure if settings with datetime-picker controller are expected to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants