In LiveView 1.0 (1.0.0-rc.7
), I am using inputs_for/1
to render forms for a nested Ash resource and it’s working great with validation of the fields in the nested resource as well as validation of the attribute with the array of the resources itself.
So, I am able to show the error below the inputs_for/1
component. However, I’m unable to immediately use used_input?/1
in order to delay showing this error until the field of the attribute for the nested resource should be considered used, after submission in this case I would like to think.
Notably, the params
do not include any entry for _unused_addresses
which would have caused used_input?/1
to work.
Is there an “idiomatic” way to handle this?
Am I holding it wrong?
The attribute in question
attribute :addresses, {:array, MyApp.MyDomain.PostalAddress},
allow_nil?: false,
public?: true
The field in the form
<.inputs_for :let={address_form} field={@form[:addresses]}>
Thank you in advance for any insights
I believe this is fixed in main
of Phoenix live view but not released yet.
1 Like
Thanks Zach but I just checked on main
and get the same result.
Maybe you’re referring to this issue?
opened 04:58PM - 27 Dec 23 UTC
closed 05:42PM - 02 Oct 24 UTC
### Environment
* Elixir version (elixir -v): 1.16.0
* Phoenix version (mix … deps): 1.7.10
* Phoenix LiveView version (mix deps): 0.20.2
* Operating system: Linux
* Browsers you attempted to reproduce this bug on (the more the merrier): Chromium
* Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: yes
### Actual behavior
Inspired by the (old) [`Phoenix.HTML.Form.datetime_select/3`](https://hexdocs.pm/phoenix_html/3.3.3/Phoenix.HTML.Form.html#datetime_select/3) and motivated by [this issue](https://github.com/kipcole9/money/issues/111), I created a `<.input type="money" ... />` component that should allow inputting a money amount and selecting its currency by using the same approach followed on `datetime_select/3` of having composite inputs for a single form value.
The problem here (which I guess is similar to the #2069 one) is that `phx-feedback-for` is not hiding the error message for untouched inputs within the same component, since `phx-feedback-for` expects you to provide it a single input name, while the custom component houses more than a single input. This behavior could be achieved by defining the `phx-feedback-for` for the custom component as well for the existing `datetime_select/3` (check the gist below).
[](https://github.com/phoenixframework/phoenix_live_view/assets/23202981/54e36486-18c0-422a-a5fd-faed6c400993)
https://gist.github.com/Wigny/07800284de5a044204b09e24a810213e
### Expected behavior
A good and expected experience would be to display the error message for all inputs derived from a `FormField` only when an invalid input has already been touched. For the example above, the error message should not be displayed since the only invalid input of the component has not been touched yet, while the other input remains valid.
I'm not sure how feasible it is to address this issue, so any guidance on how to provide a good error message experience in a composed input component like that would be really helpful.
That fix from Chris fixed used_input?/1
for the fields on the nested resource itself though.
Retracting this last reply and investigating, sorry