Hi there!
Within my form changeset there is a field that holds more than 700 records, I would paginate straight from the DB however I need all of them to be in memory, but only 5 to display on the screen. Can anybody help with this or if this is even possible at all? I need to be able to edit the form fields as well. Below is some of my code
FORM
<.form let={f}
for={@ice_cream_changeset}
id="ice-cream-edit-form"
phx-change="validate"
phx-submit="update">
<%= for {rc, index} <- Enum.with_index(inputs_for(f, :ice_cream_schemes, append: [])) do %>
<%= label rc, :cone_type, class: "block text-sm font-medium text-gray-700" %>
<%= select rc, :cone_type, ["Waffle": :waffle, "sugar": :sugar, "regular": :regular], prompt: "Choose Type" %>
<%= label rc, : flavour, class: "block text-sm font-medium text-gray-700" %>
<%= select rc, : flavour, ["vanilla": :vanilla, "strawberry": :strawberry, "chocolate": :chocolate], prompt: "Choose flavour" %>
</.form>
CHANGESET
defmodule IceCream do
@moduledoc """
"""
use Ecto.Schema
import Ecto.Changeset, warn: false
alias Data.Schemas.IceCreamScheme
@primary_key false
embedded_schema do
embeds_many(:ice_cream_schemes, IceCreamScheme)
end
def changeset(schema \\ %__MODULE__{}, params) do
schema
|> cast(params, [])
|> cast_embed(: ice_cream_schemes)
end
end
NESTED CHANGESET
defmodule Data.Schemas.IceCreamScheme do
use Ecto.Schema
import Ecto.Changeset, warn: false
@fields [
:flavour,
:cone_type
]
@primary_key false
embedded_schema do
field(:flavour, :string)
field(:cone_type, :string)
end
def changeset(schema \\ %__MODULE__{}, params) do
schema
|> cast(params, @fields)
|> validate_required(@fields)
end
end