I'm using an Ecto custom type in one of my Phoenix application's schemas, like described here (specifically, making use of Postgres Ranges to specify a range of times, like "between 12:00-4:00"). I'm able to insert/retrieve from the database without a problem, but I'm having trouble coming up with a good way to present a form for the user using changesets and Phoenix forms.
So with a schema looks like this (TimeRange
is the custom type):
@primary_key false
@foreign_key_type :binary_id
schema "person_messaging_settings" do
field :can_receive_email, :boolean, null: false
field :can_receive_sms, :boolean, null: false
field :allowed_hours, MyApp.Ecto.TimeRange
belongs_to :person, Person
timestamps()
end
I can use inputs_for
for the belongs_to
association, and ideally I could do something like this in my EEX template:
<%= form_for @changeset, Routes.settings_path(@conn, :update), fn f -> %>
<!-- other field values -->
<%= inputs_for f, :allowed_hours, fn ah -> %>
<%= time_select ah, :upper %>
<%= time_select ah, :lower %>
<% end %>
<% end %>
But this complains because inputs_for
is strictly for associations.