Opened 8 years ago

Last modified 8 years ago

#27220 closed Bug

MultiWidget not considered in form submit — at Version 2

Reported by: Andrea Angelini Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andrea Angelini)

I have a custom widget for a field, for example:

class TestWidget(MultiWidget):
    def __init__(self, attrs=None):
        widgets = (
            Select(choices=func_start()),
            Select(choices=func_end())
        )
        super(TestWidget, self).__init__(widgets, attrs)

    ...


class TestModel(models.Model)
  test = ArrayField(models.PositiveSmallIntegerField(), default=list, blank=True)


class TestForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(TestForm, self).__init__(*args, **kwargs)
        self.fields['test'].widget = SlotsWidget(self.facility)

It's been working fine until Django 10.0. With Django 10.1 and specifically due to this commit it breaks.

https://github.com/django/django/commit/4bc6b939944183533ae74791d21282e613f63a96#diff-70af885c2725fe87eb3b99a393268d10

f.name in this commit would be "test", but form.data would contain "test_0" and "test_1". For this reason form field content is skipped and not saved to the model instance.

Change History (2)

comment:1 by Andrea Angelini, 8 years ago

Description: modified (diff)

comment:2 by Andrea Angelini, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top