Skip to content
Advertisement

Deleting FlaskForm Fields depending on userinput in other forms

I have 3 forms with Checkboxes to configure the desired form (Final_Form). After the user chooses the desired fields (in form1, form2 and form3), i want to delet all fields that are not required in the final form and render the final form. The reason for that is, that i have 3 Subkategories with around 12 possible values, in each form (form1-form3) the user can choose one ore more subkategories. The subcategories are standardized and are used to describe a clinical incident. The users wished to have the subcategories (1-3; form1-form3) seperated and always with an example (right-side of the screen in an anther bootstrap col). The finalform is than a combination of the the subcategories that matches best to describe the clinical incident. All fields in the Final_Form are TextAreaFields. The Input for the TextAreaFields is stored in a sqlite-db.

Here is how i tried it:

app.py:

JavaScript

forms.py:

JavaScript

The problem is, that the formfields of the Final_Form objects dont get deleted (only inside the if statements). I am very thankful for every hint or explanation.

Advertisement

Answer

As you are showing three separate pages, there are three separate requests. You Final_Form object cannot be simply kept between these requests.

I don’t fully understand why you configure your third form this way, it would be helpful to explain your use-case for better advice.

Without more information, I’m thinking of some ways to do this:

  • You make it one page/request, where you go from form to form using AJAX.
  • You make it one page with all forms, controlling visualisation with JS + CSS
  • You save your desired value somewhere
    • probably you can keep it in cookie (session object)
    • or in database, if that makes sense in your context

Also, please include whole code of this function – it’s not clear how you create those forms you use.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement