0

In my application, on page loads by default there is a drop-down with value '3' and three input text fields.

If user selects value '2' from drop-down then number of input text fields should be changed from 3 to 2.

If user selects value '5' from drop-down then number of input text fields should be changed from prev. value to 5.

How could I do that dynamically in Django project as I am wanted to create a form in django inside forms.py?

2
  • Your question is not clear and it's very confusing. Please update your question with more details. Commented Apr 7, 2018 at 18:51
  • @Goran I updated my question. Kindly provide the solution. Commented Apr 9, 2018 at 4:12

1 Answer 1

0

There is a few different ways, but in any case you need to control a number of input fields by JavaScript. You didn't show us you model so we can't give you the best solution, but you have a following options:

  • if your form is model form, create a form with all possible fields and display/hide fields based on selected value from drop down.
  • you can use a formset_factory if your input fields belongs to the same model
  • you can add as many fields as you need by JS and process the form fields in view. This answer can be used as reference

I hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.