How to add dynamic number of text fields in django form?

How to add a char field which can grow dynamically?
Example:
On Django admin form I have only 1 text field.
Now if the user wants, can have more than 1 text fields, add data in each one of those and submit. In the backend I want to use all those fields and add to an ArrayField.
Moreover, require something like a ‘+’ sign next to the text field, which adds another text field below it.

What you’re looking for are Django’s formsets. You can build a form containing a formset with only one field. You can then add your “+” icon, and code some JavaScript, to add additional rows when requested. (How you implement this is going to depend greatly upon what JavaScript framework you may be using.)

When you process the form, you can then take all the individual entries, create a list from them, and add them to the database field.

Ken

2 Likes