Create a Dynamic JSON Schema form using a table

So I was trying to build a web admin panel for our mobile app which uses PostGreSQL database.
Now what happened was that for each table I had to manually create tables and forms for CRUD operations.
So I thought I would create a re-usable module that simply takes the table name as an input and then plug-in the module.
However while trying to do that, I ran into an issue. There doesn't seem to be any way of dynamically generating/changing the form based on table data.

I was trying to use a table and then trying to create a JSON Schema form from there, but wasn't able to find a way.

Is there a way to get the JSON schema of a form from the properties of a table somehow? columns property doesn't seem to work directly. Or is there any other way to achieve what I want to do (A Re-usable CRUD module that simply takes the table name and created CRUD for it)

Thanks,
Parth

2 Likes

Hey @Parth_Sharma!

Unfortunately, there's a bug at the moment preventing JSON Schema forms from rendering dynamic schema. Do you have a sense of how many different tables the form would need to interact with? And how different are those tables?

Also, could you describe a bit more about why it's particularly useful to your use case that you be able to dynamically generate a CRUD form? It might help in coming up with workarounds!

The use-case is what I mentioned in the original post. I'll elaborate on it.

So I have a LOT of tabs in app for doing CRUD operations on different tables, the contents of which are more or less identical, i.e. they look the same, use the same components and similar queries.
So currently for each new table/feature, I have to duplicate this tab/re-create the same interface each time I have to add CRUD functionality for a new table. I was trying to reduce this work by creating a re-usable module which would work out of the box just by passing the table name in the module inputs :slight_smile:

But due to this issue I wasn't able to do it. So wanted to know what would be the best way to accomplish this.

Do let me know if you need more info on the use-case

Hmm... You can generate a form from your table so as long as it only needs to be made once that might cut down on the time it takes but it sounds like you might already be doing that :thinking: Do you think something like this might help?

Hi @Kabirdas, any update on that bug?

My use-case is that I have a PostgreSQL table called templates, and each template has a column called template_schema which houses some JSON Schema objects.

I want to be able to query the templates table for a specific template, and then load that JSON Schema into the Retool "JSON Schema Form" component. Is that currently possible, or is the aforementioned bug still a thing?

Thanks!

Hey @Nezteb! Unfortunately, the bug is still a thing :pensive:

The main issue though is that properties aren't being removed from the form's data object. The displayed schema should update properly though and you should be able to add properties to the forms data. So one workaround might be to dynamically generate a form, and then use something like _.pick in the query attached to your form, dynamically passing it values from your template:

{{ _.pick(jsonSchemaForm1.data, _.keys(jsonSchemaForm1.jsonSchema.properties)) }}

Does that look like it could work?

1 Like

I'll give it a shot and report back!

Hey @Nezteb how did you get on with this approach?

Was this sver resolved ? Plan on switching to this method on over 30 forms...

I'd be very interested in a fast CRUD solution

Hey all! The bug hasn't been resolved yet, it doesn't look like there's a specific timeframe for it to be resolved at the moment. I've added this thread to a couple of internal requests we have regarding JSON schema forms and dynamically generated components. If there's news back on them I'll pass it along here!

In the meantime, hopefully, one of the workarounds mentioned can do the trick for you. If you find there's an issue that's a particularly big pain point in any of them please let me know.