Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Set form attribute on inputs when form is given an id

オープン
#610 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
elixir
領域
frontend

調査の方向性

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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

surface-ui/surface のほかの issue

surface-ui/surface の issue をすべて見る

似ている issue

Elixir の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。