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

Undocumented breaking change to to_form in v4.0.0 #103

Open
PolyCement opened this issue Jun 20, 2024 · 2 comments
Open

Undocumented breaking change to to_form in v4.0.0 #103

PolyCement opened this issue Jun 20, 2024 · 2 comments

Comments

@PolyCement
Copy link

Hi, I just ran into an unexpected compilation error while updating to the latest version:

    error: undefined function to_form/5 (expected MyAppWeb.LiveComponents.QuestionForm to define such a function or for it to be imported, but none are available)
    │
 37 │             to_form(@form.source, @form, :config, input_value(@form, :type), []) do
    │                    ^^^^^^^
    │
    └─ lib/mo_app_web/live/live_components/question_form.ex:37:20: MyAppWeb.LiveComponents.QuestionForm.render/1

From the docs it seems that between v3.0.7 and v4.0.0 (specifically, in commit 7fc853b) the type argument was dropped, which isn't documented in the changelog. Not a huge deal as that commit also adds a new polymorphic_type option, so changing the call as follows got it compiling again:

to_form(@form.source, @form, :config, polymorphic_type: input_value(@form, :type))

However, since both the breaking change and the options for to_form/4 are undocumented, it took some rummaging around in the repo to figure out. Maybe it'd be good to mention it in the changelog so no one else gets stumped by it like I did?

(Glad to see this project is still active btw!)

@mathieuprog
Copy link
Owner

Hi. It is undocumented because it should be internal and not supposed to be used.
This is the way to use this lib in forms:
https://github.com/mathieuprog/polymorphic_embed?tab=readme-ov-file#displaying-form-inputs-and-errors-in-liveview

Could you compare that to your code and let me know?

@PolyCement
Copy link
Author

Sorry, I didn't realise they were intended for internal use only!

I'm using a virtual field of the parent to set the embed type via a select, and the new polymorphic_embed_inputs_for component in the example you linked doesn't seem to have a type attribute that would let me use it in the same way. Using PolymorphicEmbed.HTML.Form.polymorphic_embed_inputs_for/4 as below seems to work just fine though:

polymorphic_embed_inputs_for @form, :config, input_value(@form, :type), fn config_form ->

However, to_form is also available from the Form module. Maybe the docs could state which functions are meant to be for internal use only? Either way, thanks for the help!

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

2 participants