Skip to content

Input components have their value prop overwritten in form context if it is nil #626

Description

@bartblast

Describe the bug

Suppose you've got a component that uses a Surface input component:

defmodule MyComponent do
  use Surface.LiveComponent

  data value, :string, default: nil

  def render(assigns) do
    ~F"""
    <Surface.Components.Form.HiddenInput value={@value} />
    """
  end
end

Now, if the component is used inside a Surface form context with the form having a changeset, as here:

defmodule MyForm do
  Surface.LiveComponent

  data changeset, :changeset, (some changeset value)

  def render(assigns)
    ~F"""
    <Form for={@changeset}>
      <Field name="my_field">
        <MyComponent />
      </Field>
    </Form>
    """
  end
end

Then the changeset's value always overrides the nested matching form field value in case if the data 'value' field managed by the stateful component of MyComponent is nil.

The behavior you expected

I should be able to set value prop of the input component explicitely as nil.

Your Environment

Surface: v0.7.4
LiveView: v0.17.10
Elixir: v1.13.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions