Skip to content

Datetime input does not display value correctly #69

@ediathome

Description

@ediathome

Just tried to add a datetime field to one of my forms. When showing a edit form, the datetime value is not correctly set in the html value attribute. Example:

field(:begins_at).datetime

becomes:
<input id="exam_begins_at" name="exam[begins_at]" type="datetime-local" value="2025-12-05 19:56:00 UTC" class="form-control">

The value attribute is set to '2025-12-05 19:56:00 UTC' but it should be in the form of '2025-12-06T19:56:00.01' with no timezone given (as specified here). In Safari, Firefox and Chrome this value is not accepted.

I solved the problem by setting the value manually using the DateTime strftime method:

field(:begins_at).datetime(value: model.begins_at.strftime('%FT%T'))

which becomes:

<input id="exam_begins_at" name="exam[begins_at]" type="datetime-local" value="2025-12-05T19:56:00" class="form-control">

This value attribute is accepted in Safari/FF and Chrome. I am not quite sure whether this can be implemented somewhere.

Cheers

Martin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions