Form with arbitrary number of a custom component #5142
Unanswered
EloiSanchez
asked this question in
Q&A
Replies: 1 comment
-
|
This is the same as #3718, one thing you might do is store in the state a list of objects that are the work experience information |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey. I just started to use this as an alternative to something like Streamlit to obtain a more reactive and interactive application.
Summary
I want to create a Form that allows a user to add an arbitrary amount of Work Experiences (like in a CV).
I have made a component WorkXPState that inherits from rx.ComponentState. Then I inherit this in the form page (called consultant_profile.py), but I am having trouble allowing the user to have a button that adds a new Work Experience component that they can fill in.
The FormState needs to know how many Work Experiences to display, so I have a
num_work_experiencesvariable that is incremented by 1 when the user presses a button in the form. But now I am having trouble rendering each of the Work Experience components.Code
This is the component I made. It holds the variables I want to keep track off and update in the form. It also implements the classmethod get_component, as explained in the docs, with the UI stuff that I want to render.
Then, in the page script for consultant_profile, I import the
reusable_work_xp.This is the FormState
These are the functions that I am calling from the page definition to render the work experiences in the form.
This is the definition of the page that creates the UI.
This is what I get now.
Both work experiences, added with the button
Add work experience, are modified when either of them is. I.e., If I select start year 1990 in one of them, then both of them are modified.I am having lots of trouble understanding how to have this form in a way that I can have a button to add new components that I define elsewhere. I would like to do the same with Academic Education and a Skills section.
Dooes anyone have any tip on how to make this kind of architecture, where a form can dynamically add custom components with a defined structure/UI?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions