Hi all,
I have created a set of forms using the formtools NamedUrlSessionWizardView. One of the forms in the wizard, is a django ModelForm, which contains another ModelForm, as an inline formset:
class ActivityForm(ModelForm, CrispyForm):
class Meta:
model = Activity
def adjustLayout(self):
self.helper.layout.append(
Div(
Fieldset('Add Activity Steps',
Formset('activity_steps')),
)
)
class ActivityStepForm(ModelForm, CrispyForm):
class Meta:
model = ActivityStep
def __init__(self, *args, **kwargs):
self.formtag_prefix = re.sub('-[0-9]+$', '', kwargs.get('prefix', ''))
super().__init__(*args, **kwargs)
def adjustLayout(self):
self.helper.template = f'{TEMPLATE_PACK}/table_inline_formset.html'
self.helper.all().wrap_together(Div, css_class=f'formset_row-{self.formtag_prefix}')
ActivityStepFormSet = inlineformset_factory(
Activity,
ActivityStep,
form=ActivityStepForm,
extra=1, # number of empty forms to display
can_delete=False # show a checkbox in each form to delete the row
)
The form is shown correctly, and contains a single form within the form set.
However, I want to add the ability of more forms to be added by the user.
The javascript in django-dynamic-formset seems to not work with jQuery used by crispy-forms.
What is the “most recent” way to achieve dynamic formsets?