Display inputs_for when relation it still nil
Hi everyone, I have a resource called
Person that has a has_one relationship to a contact_info resource. How can I get the inputs_for contact info to display on the front so that the user can basically "create or update" the contact info without clicking an "add contact info" button? Right now, the nested input fields do now display unless there is something already in the database for that user. Not sure if I am making sense. Thank you!7 Replies
You'd need to use
AshPhoenix.Form.add_form on mountThank you, is there a "best way" documented somewhere? I ask because sometimes the relationship WILL exist and I want to handle this scenario the right way. Thank you as always!!!
Ah, not sure if its documented specifically or not
but if not we should add it to the related forms guide.
IIRC there is a
has_form? function you can use to check if one is there first.Thank you, I will test it out shortly and mark the answer accordingly! I LOVE Ash Framework
using
add_form worked but my overall form fails to submit because there are some fields missing for example the org_id for multitenancy and some other things I was planning on "seeding" by default such as type: "phone". Like the form creates the map with my seeded fields correctly but upon submission they seems to be wiped. I could use hidden fields on the front end but if there is a way to keep this on the server that would be the best I think.Solution
You can add params to
add_formadd_form(_, %{...})I had an issue in my logic! 🤦♀️