Set form attribute on inputs when form is given an id
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Elixir
- スター
- 2.1k
- フォーク
- 146
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
surface-ui/surface のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
surface-ui/surface#634 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
surface-ui/surface#770 ·
-
Website is downオープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
surface-ui/surface#768 · コメント 4 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
surface-ui/surface#762 · コメント 2 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
surface-ui/surface#759 · リアクション 1 件 ·
surface-ui/surface の issue をすべて見る
似ている issue
-
Assigns view shows list and tuple elements in sorted order instead of their real order対応中かも @RaphaelFakhri が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
software-mansion/live-debugger#1011 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
hexlet-codebattle/codebattle#2362 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
intellij-elixir/intellij-elixir#4501 ·
メンテナーはふだん 1 日以内に返信