django-dynamic-formset and django-autocomplete-light - autocomplete does not work properly for new rows

StackOverflow https://stackoverflow.com/questions/15500392

Question

I use autocomplete-light with django-dynamic-formset. For dynamically added rows autocomplete does not work - it shows popup with autocomplete, but sticks it to last statically created row. If I choose item in list - it inserts value into last statically created row, instead of current. For statically created formset autocomplete-light works good.

It's my form and formset:

class MassSvidForm(forms.Form):
    num = CharField(label=u'Номер', required=True)
    kod_num = CharField(
                widget=autocomplete_light.TextWidget('KodZvtKod'))
    zvt_type = CharField(ZVTType.objects.all(),
            widget=autocomplete_light.TextWidget('ZVTTypeAutocomplete'))

    zvt_name = CharField(ZVTName.objects.all(),
            widget=autocomplete_light.TextWidget('ZVTNameAutocomplete'))

SvidFormset = formset_factory(
                            extra=0,
                            form=MassSvidForm,
                            can_delete=True,
                            )

svid_formset = SvidFormset(request.POST or None,
                           initial=[{
                                'template': tmpl.id,
                                'kod_num': tmpl.reservednumber.kod_zvt.kod,
                                },],
                           )

It's my js formset creation:

<script type="text/javascript">
    $(function() {
        $('#massForm tbody tr').formset({
            prefix: '{{ formset.prefix }}',
            added: (function(row) {
                $(row.find('.autocomplete-light-text-widget')).each(function() {
                    $(this).trigger('initialize');
                })
            })
        });
    })
</script>

I use Django 1.5, django-dynamic-formset 1.2, autocomplete-light 1.1.23

Was it helpful?

Solution

This was fixed in 1.1.26 thanks to your help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top