I want to make an "if this than that" rule creator, where users can continuously add new ifthan statements.
I cannot figure out a way to dynamically allow users to add new components inside a form component or any component for that matter. Closest can get is using the jsonSchemaForm, but the ui doesn't really lend itself to having multiple values in one row, if that makes sense.
Can anyone help? I'm thinking something like this:
Hmm you know I never came across this before. I wonder if this is possible directly? What I can do is check-in with my teammates to see what they are able to say about this since I haven't seen/heard of something like this before. I'll circle back with you when I find out a more solid answer.
A workaround that I can think of for the time being is to render the entire form as you'd want it and conditionally hide the values of certain components dependent on values from elsewhere in your app. The use of conditionals such as JS ternary statements can get that going for you in the right hand inspector pane under the 'hidden' option.
Hi @james.laurence !
Hopping in to help here!
While I haven't seen something directly like this myself, I have seen a use case where someone embedded a listview component within a form. From there, users can add whatever number of components within the form.
Would this work for you?
Alright, I got it. It is ListView that you have to use. And you CAN dynamically delete specific rows in the list as well. You just have to save the data for the list as a temporary state, and make the defaults for each section point to that data. Use the index of each component to identify which rows you want to delete and such. And set the length of the list to your temporary state. And for each component set it to change the temporary state, if that makes sense.
Its a bit of a pain to make the first time, but it works nicely. and in the end you have an array of objects that you can pretty easily plug into a query to update your db.
Looking up here for a solution, since the same situation came to me.
The form root entity has a one to many relationship with another object and it'd be nice to persist them all together, in one single atomic action, maintaining database consistence over the mentioned relationship.
Although I understood the proposal workaround, I'd say it is not a that rare scenario over a CRUD-kind effect of a form submission. It would be awesome to have a feature like that in here
hey @bradlymathews thanks for sharing this workaround. Is there any chance you can share a simple app with this feature so that one can make an app on top of it to see how actually it works.
@victoria@Kabirdas : Hey retool, just thinking maybe there can be some kind of incentive for user who will share apps like this with retool and retool can enhance their template library with these type of templates or update the specific docs and add these.
I've actually been running across questions like this a bunch lately. Hopefully, some of these examples give you some ideas but it would be great to get more input from other community members. I'm definitely curious to see @bradlymathews's take on this as well.
+1 on adding first-class support for an input form element where an arbitrary number of the same type of input can be added, removed, or reordered! For a single project for my company, I can already think of two input types where we'd definitely want to do this.