I have a Phoenix Liveview Form Component with multiple input fields. When a user enters an event :duration
(integer
) along with the event :open_at_date
(“2021-12-13”) and open_at_time
(“13:00:00”), I calculate the subsequent event date/time fields and put each change on the changeset. Resulting in:
changes: %{
cutoff_at: #DateTime<2021-12-14 16:30:00-05:00 EST America/New_York>,
description: "some event description",
duration: 5,
end_at: #DateTime<2021-12-17 16:30:00-05:00 EST America/New_York>,
name: "some event name",
open_at: ~U[2021-12-09 13:00:00Z], (I then convert to --> open_at: #DateTime<2021-12-13 18:00:00-05:00 EST America/New_York>,)
open_at_date: "2021-12-09",
open_at_time: "13:00:00",
rules_list: "",
start_at: #DateTime<2021-12-15 09:29:00-05:00 EST America/New_York>,
uid: "8974d16c-0f07-4191-b401-b1eae1561d3e"
},
errors: [
start_at: {"can't be blank", [validation: :required]},
end_at: {"can't be blank", [validation: :required]},
cutoff_at: {"can't be blank", [validation: :required]}
],
I’m wondering how, using Liveview, I can populate the remaining date/time input fields with the calculated DateTime values on the changeset. I assume, that I’ll also need to convert the #DateTime<...
values to _at_date
and _at_time
string values as seen for open_at_date
.