Skip to content

How can I dynamically add fields to a model? #2214

Answered by tm-3
Linxae030 asked this question in Q&A
Discussion options

You must be logged in to vote

I was looking into some similar scenarios early on and I came to the conclusion that volatile state or a normal mobx observable are better suited to this use case. The point of the nodes are to provide immutable structures as well as tracking state updates and changes, so if you're adding fields to the model after create it's not the same node anymore.

Check out the mst-form-type project if you haven't already. They created a separate model for fields and store the model in a froze type on the form. It looks like you're fairly close in the idea with what you've shown, but you'd probably be better adding items to an array and then extracting them into a view to display properly. If you're…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@coolsoftwaretyler
Comment options

Comment options

You must be logged in to vote
2 replies
@coolsoftwaretyler
Comment options

@Linxae030
Comment options

Answer selected by coolsoftwaretyler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants