Generating dynamic LiveComponent Forms from json data

Just want a bit of advice before I go to far down a rabbit hole.

I want to generate dynamic liveview forms (individual LiveComponents) based on definitions in json. Ie, given a JSON file it will at runtime generate a LiveView containing multiple LiveComponent forms each with the appropriate embedded schema Ecto changeset and LiveComponent callbacks.

I haven’t really learned Elixir metaprogramming yet, but I presume I will have to use macros for this.
Is this idea possible or recommended? Is there a better/simpler way to dynamically generate liveview forms from external data at run time?

If I can get some pointers in the right direction as someone new to macro programming that would be great!

You might be able to use schemaless changesets that are built from your json data. And then you can build the forms from changesets, no need for macros that way.

1 Like

Interesting, I wasn’t aware schemaless changesets were even possible, that definitely simplifies one aspect of it!

thanks for that tip!

I’ve created a dynamic form builders a few times in Elixir and always just used plain old functions, but what you’re doing may have been different than what I was trying to accomplish. Is there a particular aspect of what you’re trying to do that you feel might require macros?

1 Like

There doesn’t seem to be any particular need for them after all, now that I know schemaless changesets are a thing, then you’re right, just play functions can get the job done