Poll schema:
defmodule Rallly6.PollingSystem.Poll do
use Ecto.Schema
import Ecto.Changeset
alias Rallly6.PollingSystem.Option
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema “polls” do
field :description, :string
field :title, :string
field :location, :string
field :time_zone, :naive_datetime
field :is_closed, :boolean, default: false
field :is_deleted, :boolean, default: false
field :disable_comments, :boolean, default: false
field :user_id, :binary_id
has_many :options, Option
timestamps(type: :utc_datetime)
end
@doc false
def changeset(poll, attrs) do
poll
|> cast(attrs, [:title, :description, :location, :time_zone, :is_closed, :is_deleted, :disable_comments])
|> cast_assoc(:options, with: &Option.changeset/2)
|> validate_required([:title, :description, :location, :time_zone, :is_closed, :is_deleted, :disable_comments])
end
end
Option schema:
defmodule Rallly6.PollingSystem.Option do
use Ecto.Schema
import Ecto.Changeset
alias Rallly6.PollingSystem.Poll
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema “options” do
field :option_date, :date
belongs_to :poll, Poll
timestamps(type: :utc_datetime)
end
@doc false
def changeset(option, attrs) do
option
|> cast(attrs, [:option_date, :poll_id])
|> validate_required([:option_date])
end
end
form component:
<.simple_form
for={@form}
id="poll-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.input field={@form[:title]} type="text" label="Title" />
<.input field={@form[:location]} type="text" label="Location" />
<.input field={@form[:description]} type="text" label="Description" />
<.inputs_for :let={opt_nested} field={@form[:options]}>
<.input field={opt_nested[:option_date]} type="date" label="date" />
</.inputs_for>
<:actions>
<.button phx-disable-with="Saving...">Save Poll</.button>
</:actions>
</.simple_form>
</div>
In the above form component, the:option_date is not showing in the browser. I need help in fixing it