I have an ‘inlineformset_factory’, and I’m trying figure out how to set attributes for the individual fields. I haven’t come up with any way to add them besides using javascript (which would be hacky and bad).
In the end I’d like something like:
<input id="id_authorbook_set-0-title" type="text" name="authorbook_set-0-title" maxlength="255" placeholder="Title" autofocus="autofocus">
I know adding custom attributes is possible when using normal Forms or even ModelForms with attrs={'foo': 'bar', 'placeholder': 'Username'}, but haven’t been able to find any way to do the same with formset factories.
Is there a solution?
Thanks for the help.
What you describe as working, the
attrsargument, is passed to a form widget, which means you need form fields and thus a form.inlineformset_factoryis aformset_factoryfor ModelForms.Tying the two together, you need to define a custom
ModelFormand pass that to the factory as theformargument.You could also define a custom formset which iterates through the active forms, does the same overrides, and pass that to the
inlineformset_factory.