Set form attribute on inputs when form is given an id
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Start by locating the input components and their form Context handling, then inspect how form attributes are currently passed through component options. Done means inputs rendered inside a form with an id automatically receive that id as their form attribute, while existing explicit options continue to work.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When you're creating forms and associating inputs with them by using the form attribute like so
<form id="form-1"></form>
<form id="form-2"></form>
<input type="text" name="form-1-name" form="form-1" />
<input type="text" name="form-2-name" form="form-2" />
... you need to get the form from the Context and set opts={form: form.id}. It would be nice if the input components set the form attribute if the form has an id such that the below could use the IdealFormsComponent. Would you consider a PR that added this? Or should I be asking the question on phoenix_html?
defmodule MyWeb.FormsComponent do
use Surface.Component
alias Surface.Components.Context
alias Surface.Components.Form.{Field, Label, TextInput}
def render(assigns) do
~F"""
<Context get={form: form}>
<Field name={:thing}>
<Label text="Thing" form={form} />
<TextInput form={form} opts={form: form.id} />
</Field>
</Context>
"""
end
end
defmodule MyWeb.FormsComponentNamedspaceContext do
use Surface.Component
alias Surface.Components.Context
alias Surface.Components.Form.{Field, Label, TextInput}
def render(assigns) do
~F"""
<Context get={Surface.Components.Form, form: form}>
<Field name={:thing}>
<Label text="Thing" />
<TextInput opts={form: form.id} />
</Field>
</Context>
"""
end
end
defmodule MyWeb.IdealFormsComponent do
use Surface.Component
alias Surface.Components.Context
alias Surface.Components.Form.{Field, Label, TextInput}
def render(assigns) do
~F"""
<Field name={:thing}>
<Label text="Thing" />
<TextInput />
</Field>
"""
end
end
defmodule MyWeb.FormsLive do
use MyWeb, :surface_live_view
alias MyWeb.FormsComponent
alias MyWeb.FormsComponentNamedspaceContext
alias Surface.Components.Context
@impl true
def mount(_params, _session, socket) do
{:ok,
assign(socket,
thing1: changeset(%{thing: "thing1"}),
thing2: changeset(%{thing: "thing2"})
)}
end
defp changeset(data \\ %{}, params) do
types = %{thing: :string}
Ecto.Changeset.cast({data, types}, params, Map.keys(types))
end
@impl true
def render(assigns) do
~F"""
<main>
{form1 =
form_for(@thing1, "#",
as: :thing1,
id: "thing1form",
phx_change: "change1",
autocomplete: "off"
)}
<#Raw></form></#Raw>
{form2 =
form_for(@thing2, "#",
as: :thing2,
id: "thing2form",
phx_change: "change2",
autocomplete: "off"
)}
<#Raw></form></#Raw>
{!--
<Context put={Surface.Components.Form, form: form1}>
<IdealFormsComponent />
</Context>
--}
<Context put={Surface.Components.Form, form: form1}>
<FormsComponentNamedspaceContext />
</Context>
<Context put={form: form2}>
<FormsComponent />
</Context>
</main>
"""
end
@impl true
def handle_event(event, params, socket) do
IO.inspect([event, params], label: "forms live")
{:noreply, socket}
end
end
- Lingua principale
- Elixir
- Stelle
- 2.1k
- Fork
- 146
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di surface-ui/surface
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
surface-ui/surface#634 · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
surface-ui/surface#770 ·
-
Website is downAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
surface-ui/surface#768 · 4 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
surface-ui/surface#762 · 2 commenti · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
surface-ui/surface#759 · 1 reazione ·
Tutte le issue di surface-ui/surface
Issue simili
-
bug(dashboard): gate card last-seen badge shows inventory-sync timestamp, not sweep observation timeAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
carverauto/serviceradar#5793 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
expert-lsp/expert#942 ·
I maintainer di solito rispondono entro 1 giorno
-
npm: file fetcher aborts with "engines.<key> must be a string" when package.json engines contains a nested object (e.g. cordovaDependencies)Forse già presa @v-sachin-sandhu l’ha presa oggi. ApertaL: javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
dependabot/dependabot-core#16615 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug priority: medium
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 93/100
TomerAberbach/profiler-md#732 ·
I maintainer di solito rispondono entro 1 giorno