-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
simple_form default for @as overrides form values #5901
Comments
The issue is in the generated simple_form: You can see it sets the default of |
Thank you @josevalim for having a look! I suppose the suggestion of using And if there is anything else I can do to help moving this forward, please let me know. |
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)[phoenixframework#5901]. Fixes phoenixframework#5901
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](phoenixframework#5901). Fixes phoenixframework#5901
While using the
simple_form
component (that is generated by default usingmix phx.new
), the following problem grabbed my attention. I was building a form schema inside a live view and wanted to render that form using thesimple_form
component.The example states that it should be used like this
But I thought, that it would be more consistent to use the
<.simple_form :let={f} for={@form}>
in my case (because I was likely to also useinputs_for
in that project). But using:let
does cause the structf
to containnil
as it's name, which in turn messes up the field names and value groupings of the form (as the prefix based on the schema name is missing).Currently, the following code:
produces the following results
Which seems odd to me.
I prepared an example repository that can be used to reproduce the issue.
The text was updated successfully, but these errors were encountered: