Only the title, location, and description fields are showing in the form. The option_date field is not showing in the browser.

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:

<.header> <%!-- <%= @title %> --%> <:subtitle>Use this form to manage poll records in your database.
  <.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

Hello and welcome to the community.

How are you creating the @form assigns in your controller?

Like this and this form component auto-generated and modifying based on my need.

defmodule Rallly6Web.CreatePollLive.FormComponent do
use Rallly6Web, :live_component

alias Rallly6.PollingSystem

@impl true
def render(assigns) do
~H"“”


<.header>
<%!-- <%= @title %> --%>
<:subtitle>Use this form to manage poll records in your database.</:subtitle>
</.header>

  <.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>
"""

end

@impl true
def update(assigns, socket) do

{:ok,
 socket
 |> assign(assigns)
 |> assign_form(assigns.poll_changeset)}

end

@impl true
def handle_event(“validate”, poll_params, socket) do
changeset =
socket.assigns.poll
|> PollingSystem.change_poll(poll_params)
|> Map.put(:action, :validate)

{:noreply, socket}

end

defp assign_form(socket, %Ecto.Changeset{} = changeset) do
assign(socket, :form, to_form(changeset))
end

end