LoginSignup
0
0

More than 1 year has passed since last update.

datetime-localの罠

Posted at

はじめに

Railsにてポートフォリオ作成時、動作確認を行う中で、日時のフォームにdatetime-localを使用している箇所で、不都合なことが起きたため、まとめたものです。

type=datetime-local

下記のように、日時を登録するフォームを生成するもの。
image.png
railsのform_with使用時は以下で製作可能

<%= f.datetime_field :start_time, ...

不都合① safari

iphoneを用いて動作確認中に、予定を新規作成しようとした際、保存を押しても"有効な値を入力してください"と言われてしまう。

対応策としては、初期値を代入することで回避は可能

<%= f.datetime_field :start_time, value: Time.current.strftime("%Y-%m-%dT%H:00:00") %>

不都合② Firefox

Firefoxではそもそも対応していない

image.png

そのため、間の"T"を消して登録などを押されると、不正な値として送信していることになる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0