Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bartblast opened this issue Jul 28, 2022 · 0 comments

Comments

@bartblast
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant