Using multiple empty_forms in django

I am using multiple empty_form attribute in a form and they seem to have the same id’s so i cannot manipulate them individually with jquery because all actions go to the first empty form with the corresponding Iddespite using the prefix

I assume you’re talking about formsets here.

Yes, there are unique identifiers per form - it’s basically the prefix followed by what I would call the form sequence number.

However, I can’t think of any situation where I’ve needed to reference a form by ID. When I’m doing such things, my jQuery selectors identify the form containing the element being selected. If you supply more specific details about what it is you’re trying to accomplish, we might be able to offer more tangible solutions.

Ken

1 Like

The formset attribute empty_form automatically creates multiple input fields with unique ids as shown in the image below. And I want to use multiple empty_forms in the same form. And I dont know how to make thier ids unique.

By default the prefix will be form if none is passed. Docs

In your views you can define something like CustomFormset(prefix='customPrefix')

Or look at the example from the docs.

Omg…I just realised I was adding the prefix to the formset in the post request…thank you for the reference to the docs tho…it made me realise my mistake.