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 on form doesn't work with datetime #333

Open
ManiMozaffar opened this issue Jun 10, 2024 · 1 comment
Open

Initial value on form doesn't work with datetime #333

ManiMozaffar opened this issue Jun 10, 2024 · 1 comment

Comments

@ManiMozaffar
Copy link
Contributor

When I have a form with datetime with initial value, it doesn't respect the initial value

class SomeForm(BaseModel):
     start_date: datetime
     
c.ModalForm(model=SomeForm, initial=SomeForm(start_date=datetime.now(UTC))

Screenshot 2024-06-10 at 12 29 57

@arrshad
Copy link

arrshad commented Jun 12, 2024

For now, you can use strftime with formats such as %Y-%m-%d for date and %Y-%m-%d %H:%M for datetime. You can implement this in SomeForm to convert the date to a string.

datetime.now(UTC).strftime('%Y-%m-%d %H:%M')

This behavior is due to the format that the value field in the input tag with type="datetime-local" can accept.

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