Itzel Bracho Molina
Itzel Bracho Molina

Reputation: 188

how to add a javascript event in a formset?

I want to add an onchange event to the formset, I tried to do this in views.py, but it adds this error to me:

'name':input(attrs={
TypeError: input() takes no keyword arguments

views.py

    ParteFormSet = formset_factory(ParteForm, extra=extra_forms, max_num=20, widgets={
        'name':input(attrs={
            'onchange': 'multiplicar()'
        })
    })
    formset = ParteFormSet()

Upvotes: 0

Views: 60

Answers (1)

yagus
yagus

Reputation: 1445

First, you have to define the widget in the parent form ('ParteForm'), not in the formset_factory function.

Second, input() is not a Django widget. Actually, you're invoking Python's input() function, which is definitely not what you want.

Instead use a valid Django built-in widget class (see list here). For example, forms.TextInput().

Upvotes: 1

Related Questions