phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.46k stars 2.88k forks source link

Preserve original name when `as` is not provided to `simple_form` #5975

Closed rmoorman closed 1 hour ago

rmoorman commented 1 week ago

Remove the default nil value for the as attribute in the generated simple_form core component.

This default interferes with the form name present in the form struct provided through the component's for attribute when used with :let=.

For example, consider the following code:

<.simple_form :let={f} for={@form}>
  <%= inspect(f.name) %>
  <.input field={f[:bar]} label="Bar" />
</.simple_form>

When rendered, f.name is nil, and the name attribute of the form field only contains bar, missing the proper field name prefix from the form struct:

<div class="mt-10 space-y-8 bg-white">
  nil
  <div data-phx-id="m9-phx-GAgAfRg6YU4XV6tC">
    <label for="bar" class="block text-sm font-semibold leading-6 text-zinc-800" data-phx-id="m10-phx-GAgAfRg6YU4XV6tC">
    Bar
    </label>
    <input type="text" name="bar" id="bar" class="mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6 border-zinc-300 focus:border-zinc-400">
  </div>
</div>

This issue been reported over here.

Fixes phoenixframework/phoenix#5901

SteffenDE commented 1 hour ago

Thank you! 🙌